Skip to content

Commit 41be99f

Browse files
committed
initial check-in of webpack template
0 parents  commit 41be99f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1848
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
docs/_book

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# vue-webpack-boilerplate
2+
3+
> A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.
4+
5+
> This template is Vue 2.0 compatible. For Vue 1.x use this command: `vue init webpack#1.0 my-project`
6+
7+
## Documentation
8+
9+
- [For this template](http://vuejs-templates.github.io/webpack): common questions specific to this template are answered and each part is described in greater detail
10+
- [For Vue 2.0](http://vuejs.org/guide/): general information about how to work with Vue, not specific to this template
11+
12+
## Usage
13+
14+
This is a project template for [vue-cli](https://github.com/vuejs/vue-cli). **It is recommended to use npm 3+ for a more efficient dependency tree.**
15+
16+
``` bash
17+
$ npm install -g vue-cli
18+
$ vue init webpack my-project
19+
$ cd my-project
20+
$ npm install
21+
$ npm run dev
22+
```
23+
24+
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.
25+
26+
## What's Included
27+
28+
- `npm run dev`: first-in-class development experience.
29+
- Webpack + `vue-loader` for single file Vue components.
30+
- State preserving hot-reload
31+
- State preserving compilation error overlay
32+
- Lint-on-save with ESLint
33+
- Source maps
34+
35+
- `npm run build`: Production ready build.
36+
- JavaScript minified with [UglifyJS](https://github.com/mishoo/UglifyJS2).
37+
- HTML minified with [html-minifier](https://github.com/kangax/html-minifier).
38+
- CSS across all components extracted into a single file and minified with [cssnano](https://github.com/ben-eb/cssnano).
39+
- 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.
40+
- Use `npm run build --report`to build with bundle size analytics.
41+
42+
- `npm run unit`: Unit tests run in PhantomJS with [Karma](http://karma-runner.github.io/0.13/index.html) + [Mocha](http://mochajs.org/) + [karma-webpack](https://github.com/webpack/karma-webpack).
43+
- Supports ES2015+ in test files.
44+
- Supports all webpack loaders.
45+
- Easy mock injection.
46+
47+
- `npm run e2e`: End-to-end tests with [Nightwatch](http://nightwatchjs.org/).
48+
- Run tests in multiple browsers in parallel.
49+
- Works with one command out of the box:
50+
- Selenium and chromedriver dependencies automatically handled.
51+
- Automatically spawns the Selenium server.
52+
53+
### Fork It And Make Your Own
54+
55+
You can fork this repo to create your own boilerplate, and use it with `vue-cli`:
56+
57+
``` bash
58+
vue init username/repo my-project
59+
```

circle.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
machine:
2+
node:
3+
version: 6
4+
5+
test:
6+
override:
7+
- bash test.sh

deploy-docs.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cd docs
2+
rm -rf _book
3+
gitbook build
4+
cd _book
5+
git init
6+
git add -A
7+
git commit -m 'update book'
8+
git push -f [email protected]:vuejs-templates/webpack.git master:gh-pages

docs/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Introduction
2+
3+
This boilerplate is targeted towards large, serious projects and assumes you are somewhat familiar with Webpack and `vue-loader`. Make sure to also read [`vue-loader`'s documentation](http://vuejs.github.io/vue-loader/index.html) for common workflow recipes.
4+
5+
If you just want to try out `vue-loader` or whip out a quick prototype, use the [webpack-simple](https://github.com/vuejs-templates/webpack-simple) template instead.
6+
7+
## Quickstart
8+
9+
To use this template, scaffold a project with [vue-cli](https://github.com/vuejs/vue-cli). **It is recommended to use npm 3+ for a more efficient dependency tree.**
10+
11+
``` bash
12+
$ npm install -g vue-cli
13+
$ vue init webpack my-project
14+
$ cd my-project
15+
$ npm install
16+
$ npm run dev
17+
```

docs/SUMMARY.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Summary
2+
3+
- [Project Structure](structure.md)
4+
- [Build Commands](commands.md)
5+
- [Linter Configuration](linter.md)
6+
- [Pre-Processors](pre-processors.md)
7+
- [Handling Static Assets](static.md)
8+
- [Environment Variables](env.md)
9+
- [Integrate with Backend Framework](backend.md)
10+
- [API Proxying During Development](proxy.md)
11+
- [Unit Testing](unit.md)
12+
- [End-to-end Testing](e2e.md)
13+
- [Prerendering for SEO](prerender.md)

docs/backend.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Integrating with Backend Framework
2+
3+
If you are building a purely-static app (one that is deployed separately from the backend API), then you probably don't even need to edit `config/index.js`. However, if you want to integrate this template with an existing backend framework, e.g. Rails/Django/Laravel, which comes with their own project structures, you can edit `config/index.js` to directly generate front-end assets into your backend project.
4+
5+
Let's take a look at the default `config/index.js`:
6+
7+
``` js
8+
var path = require('path')
9+
10+
module.exports = {
11+
build: {
12+
index: path.resolve(__dirname, 'dist/index.html'),
13+
assetsRoot: path.resolve(__dirname, 'dist'),
14+
assetsSubDirectory: 'static',
15+
assetsPublicPath: '/',
16+
productionSourceMap: true
17+
},
18+
dev: {
19+
port: 8080,
20+
proxyTable: {}
21+
}
22+
}
23+
```
24+
25+
Inside the `build` section, we have the following options:
26+
27+
### `build.index`
28+
29+
> Must be an absolute path on your local file system.
30+
31+
This is where the `index.html` (with injected asset URLs) will be generated.
32+
33+
If you are using this template with a backend-framework, you can edit `index.html` accordingly and point this path to a view file rendered by your backend app, e.g. `app/views/layouts/application.html.erb` for a Rails app, or `resources/views/index.blade.php` for a Laravel app.
34+
35+
### `build.assetsRoot`
36+
37+
> Must be an absolute path on your local file system.
38+
39+
This should point to the root directory that contains all the static assets for your app. For example, `public/` for both Rails/Laravel.
40+
41+
### `build.assetsSubDirectory`
42+
43+
Nest webpack-generated assets under this directory in `build.assetsRoot`, so that they are not mixed with other files you may have in `build.assetsRoot`. For example, if `build.assetsRoot` is `/path/to/dist`, and `build.assetsSubDirectory` is `static`, then all Webpack assets will be generated in `path/to/dist/static`.
44+
45+
This directory will be cleaned before each build, so it should only contain assets generated by the build.
46+
47+
Files inside `static/` will be copied into this directory as-is during build. This means if you change this prefix, all your absolute URLs referencing files in `static/` will also need to be changed. See [Handling Static Assets](static.md) for more details.
48+
49+
### `build.assetsPublicPath`
50+
51+
This should be the URL path where your `build.assetsRoot` will be served from over HTTP. In most cases, this will be root (`/`). Only change this if your backend framework serves static assets with a path prefix. Internally, this is passed to Webpack as `output.publicPath`.
52+
53+
### `build.productionSourceMap`
54+
55+
Whether to generate source maps for production build.
56+
57+
### `dev.port`
58+
59+
Specify the port for the dev server to listen to.
60+
61+
### `dev.proxyTable`
62+
63+
Define proxy rules for the dev server. See [API Proxying During Development](proxy.md) for more details.

docs/commands.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build Commands
2+
3+
All build commands are executed via [NPM Scripts](https://docs.npmjs.com/misc/scripts).
4+
5+
### `npm run dev`
6+
7+
> Starts a Node.js local development server. See [API Proxying During Development](proxy.md) for more details.
8+
9+
- Webpack + `vue-loader` for single file Vue components.
10+
- State preserving hot-reload
11+
- State preserving compilation error overlay
12+
- Lint-on-save with ESLint
13+
- Source maps
14+
15+
### `npm run build`
16+
17+
> Build assets for production. See [Integrating with Backend Framework](backend.md) for more details.
18+
19+
- JavaScript minified with [UglifyJS](https://github.com/mishoo/UglifyJS2).
20+
- HTML minified with [html-minifier](https://github.com/kangax/html-minifier).
21+
- CSS across all components extracted into a single file and minified with [cssnano](https://github.com/ben-eb/cssnano).
22+
- 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.
23+
24+
### `npm run unit`
25+
26+
> Run unit tests in PhantomJS with [Karma](https://karma-runner.github.io/). See [Unit Testing](unit.md) for more details.
27+
28+
- Supports ES2015+ in test files.
29+
- Supports all webpack loaders.
30+
- Easy [mock injection](http://vuejs.github.io/vue-loader/en/workflow/testing-with-mocks.html).
31+
32+
### `npm run e2e`
33+
34+
> Run end-to-end tests with [Nightwatch](http://nightwatchjs.org/). See [End-to-end Testing](e2e.md) for more details.
35+
36+
- Run tests in multiple browsers in parallel.
37+
- Works with one command out of the box:
38+
- Selenium and chromedriver dependencies automatically handled.
39+
- Automatically spawns the Selenium server.

docs/e2e.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# End-to-end Testing
2+
3+
This boilerplate uses [Nightwatch.js](http://nightwatchjs.org) for e2e tests. Nightwatch.js is a highly integrated e2e test runner built on top of Selenium. This boilerplate comes with Selenium server and chromedriver binaries pre-configured for you, so you don't have to mess with these yourself.
4+
5+
Let's take a look at the files in the `test/e2e` directory:
6+
7+
- `runner.js`
8+
9+
A Node.js script that starts the dev server, and then launches Nightwatch to run tests against it. This is the script that will run when you run `npm run e2e`.
10+
11+
- `nightwatch.conf.js`
12+
13+
Nightwatch configuration file. See [Nightwatch's docs on configuration](http://nightwatchjs.org/guide#settings-file) for more details.
14+
15+
- `custom-assertions/`
16+
17+
Custom assertions that can be used in Nightwatch tests. See [Nightwatch's docs on writing custom assertions](http://nightwatchjs.org/guide#writing-custom-assertions) for more details.
18+
19+
- `specs/`
20+
21+
Your actual tests! See [Nightwatch's docs on writing tests](http://nightwatchjs.org/guide#writing-tests) and [API reference](http://nightwatchjs.org/api) for more details.
22+
23+
### Running Tests in More Browsers
24+
25+
To configure which browsers to run the tests in, add an entry under "test_settings" in [`test/e2e/nightwatch.conf.js`](https://github.com/vuejs-templates/webpack/blob/master/template/test/e2e/nightwatch.conf.js#L17-L39) , and also the `--env` flag in [`test/e2e/runner.js`](https://github.com/vuejs-templates/webpack/blob/master/template/test/e2e/runner.js#L15). If you wish to configure remote testing on services like SauceLabs, you can either make the Nightwatch config conditional based on environment variables, or use a separate config file altogether. Consult [Nightwatch's docs on Selenium](http://nightwatchjs.org/guide#selenium-settings) for more details.

docs/env.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Environment Variables
2+
3+
Sometimes it is practical to have different config values according to the environment that the application is running in.
4+
5+
As an example:
6+
7+
```js
8+
// config/prod.env.js
9+
module.exports = {
10+
NODE_ENV: '"production"',
11+
DEBUG_MODE: false,
12+
API_KEY: '"..."' // this is shared between all environments
13+
}
14+
15+
// config/dev.env.js
16+
module.exports = merge(prodEnv, {
17+
NODE_ENV: '"development"',
18+
DEBUG_MODE: true // this overrides the DEBUG_MODE value of prod.env
19+
})
20+
21+
// config/test.env.js
22+
module.exports = merge(devEnv, {
23+
NODE_ENV: '"testing"'
24+
})
25+
```
26+
27+
> **Note:** string variables need to be wrapped into single and double quotes `'"..."'`
28+
29+
So, the environment variables are:
30+
- Production
31+
- NODE_ENV = 'production',
32+
- DEBUG_MODE = false,
33+
- API_KEY = '...'
34+
- Development
35+
- NODE_ENV = 'development',
36+
- DEBUG_MODE = true,
37+
- API_KEY = '...'
38+
- Testing
39+
- NODE_ENV = 'testing',
40+
- DEBUG_MODE = true,
41+
- API_KEY = '...'
42+
43+
As we can see, `test.env` inherits the `dev.env` and the `dev.env` inherits the `prod.env`.
44+
45+
### Usage
46+
47+
It is simple to use the environment variables in your code. For example:
48+
49+
```js
50+
Vue.config.debug = process.env.DEBUG_MODE
51+
```

docs/linter.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Linter Configuration
2+
3+
This boilerplate uses [ESLint](http://eslint.org/) as the linter, and uses the [Standard](https://github.com/feross/standard/blob/master/RULES.md) preset with some small customizations.
4+
5+
If you are not happy with the default linting rules, you have several options:
6+
7+
1. Overwrite individual rules in `.eslintrc.js`. For example, you can add the following rule to enforce semicolons instead of omitting them:
8+
9+
``` js
10+
"semi": [2, "always"]
11+
```
12+
13+
2. Pick a different ESLint preset when generating the project, for example [eslint-config-airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb).
14+
15+
3. Pick "none" for ESLint preset when generating the project and define your own rules. See [ESLint documentation](http://eslint.org/docs/rules/) for more details.

docs/pre-processors.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Pre-Processors
2+
3+
This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, SASS, Stylus, and PostCSS. To use a pre-processor, all you need to do is installing the appropriate webpack loader for it. For example, to use SASS:
4+
5+
``` bash
6+
npm install sass-loader node-sass --save-dev
7+
```
8+
9+
Note you also need to install `node-sass` because `sass-loader` depends on it as a peer dependency.
10+
11+
### Using Pre-Processors inside Components
12+
13+
Once installed, you can use the pre-processors inside your `*.vue` components using the `lang` attribute on `<style>` tags:
14+
15+
``` html
16+
<style lang="scss">
17+
/* write SASS! */
18+
</style>
19+
```
20+
21+
### A note on SASS syntax
22+
23+
- `lang="scss"` corresponds to the CSS-superset syntax (with curly braces and semicolones).
24+
- `lang="sass"` corresponds to the indentation-based syntax.
25+
26+
### PostCSS
27+
28+
Styles in `*.vue` files are piped through PostCSS by default, so you don't need to use a specific loader for it. You can simply add PostCSS plugins you want to use in `build/webpack.base.conf.js` under the `vue` block:
29+
30+
``` js
31+
// build/webpack.base.conf.js
32+
module.exports = {
33+
// ...
34+
vue: {
35+
postcss: [/* your plugins */]
36+
}
37+
}
38+
```
39+
40+
See [vue-loader's related documentation](http://vuejs.github.io/vue-loader/en/features/postcss.html) for more details.
41+
42+
### Standalone CSS Files
43+
44+
To ensure consistent extraction and processing, it is recommended to import global, standalone style files from your root `App.vue` component, for example:
45+
46+
``` html
47+
<!-- App.vue -->
48+
<style src="./styles/global.less" lang="less"></style>
49+
```
50+
51+
Note you should probably only do this for the styles written by yourself for your application. For existing libraries e.g. Bootstrap or Semantic UI, you can place them inside `/static` and reference them directly in `index.html`. This avoids extra build time and also is better for browser caching. (See [Static Asset Handling](static.md))

0 commit comments

Comments
 (0)