Skip to content

Commit dc8b13c

Browse files
committed
almost done
1 parent c3bb03f commit dc8b13c

File tree

6 files changed

+89
-3
lines changed

6 files changed

+89
-3
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
- [Scoped CSS](features/scoped-css.md)
1313
- [Hot Reload](features/hot-reload.md)
1414
- Workflow
15+
- [Production Build](workflow/production.md)
1516
- [Linting](workflow/linting.md)
1617
- [Testing](workflow/testing.md)
17-
- [Production Build](workflow/production.md)

docs/features/hot-reload.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ The easiest setup for enabling hot reload is what we outlined in the [basic tuto
1010

1111
``` js
1212
// package.json
13+
...
1314
"scripts": {
1415
"dev": "webpack-dev-server --inline --hot"
1516
}
17+
...
1618
```
1719

1820
This is assuming that you are serving the same `index.html` from the root of your project. By default, Webpack dev server uses the current working directory as its content base and serves all static files in the directory.

docs/start/tutorial.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ Finally, it's time to get it running! We will simply use [NPM scripts](https://d
157157
``` json
158158
...
159159
"scripts": {
160-
"dev": "webpack-dev-server --inline --hot"
160+
"dev": "webpack-dev-server --inline --hot",
161+
"build": "webpack -p"
161162
}
162163
...
163164
```
@@ -168,7 +169,13 @@ Then run:
168169
npm run dev
169170
```
170171

171-
And you should see your app working at `http://localhost:8080`, with hot-reloading enabled!
172+
And you should see your app working at `http://localhost:8080`, with hot-reloading enabled! To build, minify and write your bundle to disk, run:
173+
174+
``` bash
175+
npm run build
176+
```
177+
178+
Note that Webpack uses the `webpack.config.js` if it finds one. If you named your Webpack config file with a different name, you need to specify it using the `--config /path/to/your/file` command line option.
172179

173180
---
174181

docs/workflow/linting.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Linting
2+
3+
You may have been wondering how do you lint your code inside `*.vue` files, since they are not JavaScript. We will assume you are using [ESLint](http://eslint.org/) (if you are not, you should!).
4+
5+
When using ESLint directly, you can use it with the [eslint-html-plugin](https://github.com/BenoitZugmeyer/eslint-plugin-html) with also supports extracting and linting the JavaScript inside `*.vue` files.
6+
7+
Another option is using the [eslint-loader](https://github.com/MoOx/eslint-loader), and configure it to lint the JavaScript code in `*.vue` files directly:
8+
9+
``` bash
10+
npm install eslint eslint-loader --save-dev
11+
```
12+
13+
``` js
14+
// webpack.config.js
15+
module.exports = {
16+
// ... other options
17+
vue: {
18+
loaders: {
19+
js: 'babel!eslint'
20+
}
21+
},
22+
babel: {
23+
presets: ['es2015'],
24+
plugins: ['transform-runtime']
25+
}
26+
}
27+
```
28+
29+
Two things to note here:
30+
31+
1. We are overwriting the default loader string for all JavaScript in `*.vue` files - if we still want ES2015, we need to explicitly apply `babel-loader` and related configurations.
32+
33+
2. Webpack loader chains are applied right-first. Make sure to apply `eslint` before `babel` so we are linting the pre-compile source code.
34+
35+
And don't forget to create your `.eslintrc` config. Now when you run `webpack-dev-server`, you'll get instant lint warnings as you save the file!

docs/workflow/production.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Production Build
2+
3+
There are two things to do when building our bundle for production:
4+
5+
1. Minify our application code;
6+
2. Use the [setup described in the Vue.js guide](http://vuejs.org/guide/application.html#Deploying_for_Production) to strip all the warnings from Vue.js source code.
7+
8+
Here's an example config:
9+
10+
``` js
11+
// webpack.config.js
12+
module.exports = {
13+
// ... other options
14+
plugins: [
15+
// short-circuits all Vue.js warning code
16+
new webpack.DefinePlugin({
17+
'process.env': {
18+
NODE_ENV: '"production"'
19+
}
20+
}),
21+
// minify with dead-code elimination
22+
new webpack.optimize.UglifyJsPlugin({
23+
compress: {
24+
warnings: false
25+
}
26+
}),
27+
// optimize module ids by occurence count
28+
new webpack.optimize.OccurenceOrderPlugin()
29+
]
30+
}
31+
```
32+
33+
Obviously we don't want to use this config during development, so there are several ways to approach this:
34+
35+
1. Dynamically build up the configuration object based on an environment variable, as shown in [vue-loader-example](https://github.com/vuejs/vue-loader-example/blob/master/webpack.config.js#L40-L56);
36+
37+
2. Use two separate Webpack config files, one for development and one for production. And maybe share some common options between them in a third file.
38+
39+
It's really up to you as long as it achieves the goal.

docs/workflow/testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Testing
2+
3+
### Karma + karma-webpack

0 commit comments

Comments
 (0)