A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.
This is a project template for vue-cli.
$ npm install -g vue-cli
$ vue init webpack my-project
$ cd my-project
$ npm install
$ npm run dev
-
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.
-
npm test
: Unit tests run in PhantomJS with Karma + karma-jasmine + karma-webpack.- Supports ES2015 in test files.
- Supports all webpack loaders.
- Easy mock injection.
For detailed explanation on how things work, consult the docs for vue-loader.
You will likely need to do some tuning to suit your own needs:
-
Install additional libraries that you need, e.g.
vue-router
,vue-resource
,vuex
, etc... -
Use your preferred
.eslintrc
config. -
Add your preferred CSS pre-processor, for example:
npm install less-loader --save-dev
-
Working with an existing backend server:
- The dev server is simply an Express server with webpack-dev-middleware and webpack-hot-middleware pre-configured. You can add your own routing rules to
build/dev-server.js
to proxy certain requests to an existing backend server. Or, if you are using Express yourself, you can simply copy the middleware configuration, but make sure to add them only in development mode!
- The dev server is simply an Express server with webpack-dev-middleware and webpack-hot-middleware pre-configured. You can add your own routing rules to
-
For unit testing:
-
You can run the tests in multiple real browsers by installing more karma launchers and adjusting the
browsers
field inbuild/karma.conf.js
. -
You can also swap out Jasmine for other testing frameworks, e.g. use Mocha with karma-mocha.
-
You can fork this repo to create your own boilerplate, and use it with vue-cli
:
vue init username/repo my-project