assumes the following structure
app
- backend (sails new backend)
- assets
- index.html
- frontend (vue init towc/vue-template-webpack-sails frontend)
The assets/index.html
can then be used for any purpose.
Watching has been enabled with aggregateTimeout: 0
and poll: 100
for fast changing, without a hot reload. This means that after, ideally in a separate terminal, you can call npm run build
and the various files in backend/assets
will be automatically updated, so hard-refreshing the page is all that is needed, without having to run sails lift
again.
I've also took the liberty to add bulma. To disable it, just comment the import 'bulma/css/bulma.css'
line at the beginning of frontend/src/main.js
. With this you can simply use the classes provided by bulma anywhere in your <templates>
, or index.html
, or however you want to add them, as long as vue is managing it.
In addition, ESLint has been disabled by default due to it being buggy, so you can just press ENTER
during the vue setup, but still change anything you might want. And finally mode: 'history'
has been enabled by default on the vue-router
In order to call the file using different paths, it is recommended to use this structure in sails' backend/config/routes.js
:
const paths = [ '/', '/#', '/profile', ... ]
, vue = 'Vue.serve'
, pathObject = {};
paths.map( path => pathObject[ path ] = vue );
module.exports.routes = Object.assign( pathObject, {
'post /api/stuff': 'Whatever.action'
...
});
Where Vue
is just a controller (sails generate controller vue
) to which a serve
action is called in backend/api/controllers/VueController.js
:
const fs = require( 'fs' )
, vuePath = __dirname + '/../../assets/index.html';
module.exports = {
serve( req, res ) {
fs.exists( vuePath, ( exists ) => {
if( !exists )
return res.notFound( 'Vue hasn\'t been built yet' );
fs.createReadStream( vuePath ).pipe( res );
})
}
}
The rest of the readme is from the original vuejs-templates/webpack
A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.
This template is Vue 2.0 compatible. For Vue 1.x use this command:
vue init webpack#1.0 my-project
- For this template: common questions specific to this template are answered and each part is described in greater detail
- For Vue 2.0: general information about how to work with Vue, not specific to this template
This is a project template for vue-cli. It is recommended to use npm 3+ for a more efficient dependency tree.
$ npm install -g vue-cli
$ vue init webpack my-project
$ cd my-project
$ npm install
$ npm run dev
If port 8080 is already in use on your machine you must change the port number in /config/index.js
. Otherwise npm run dev
will fail.
-
npm run dev
: first-in-class development experience.- Webpack +
vue-loader
for single file Vue components. - State preserving hot-reload
- State preserving compilation error overlay
- Lint-on-save with ESLint
- Source maps
- Webpack +
-
npm run build
: Production ready build.- JavaScript minified with UglifyJS.
- HTML minified with html-minifier.
- CSS across all components extracted into a single file and minified with cssnano.
- All static assets compiled with version hashes for efficient long-term caching, and a production
index.html
is auto-generated with proper URLs to these generated assets. - Use
npm run build --report
to build with bundle size analytics.
-
npm run unit
: Unit tests run in PhantomJS with Karma + Mocha + karma-webpack.- Supports ES2015+ in test files.
- Supports all webpack loaders.
- Easy mock injection.
-
npm run e2e
: End-to-end tests with Nightwatch.- Run tests in multiple browsers in parallel.
- Works with one command out of the box:
- Selenium and chromedriver dependencies automatically handled.
- Automatically spawns the Selenium server.
You can fork this repo to create your own boilerplate, and use it with vue-cli
:
vue init username/repo my-project