Skip to content
This repository was archived by the owner on Jun 14, 2018. It is now read-only.

Commit 353e70c

Browse files
authored
Merge pull request #2 from ryutamaki/feature/webpack2
webpack v2
2 parents 876dbb4 + 4c3fe47 commit 353e70c

26 files changed

+255
-187
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $ npm run dev
3434
- HTML minified with [html-minifier](https://github.com/kangax/html-minifier).
3535
- CSS across all components extracted into a single file and minified with [cssnano](https://github.com/ben-eb/cssnano).
3636
- 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.
37+
- Use `npm run build --report`to build with bundle size analytics.
3738

3839
- `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).
3940
- Supports typescript in test files.

circle.yml

Lines changed: 7 additions & 0 deletions
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

docs/proxy.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ module.exports = {
2424
```
2525

2626
The above example will proxy the request `/api/posts/1` to `http://jsonplaceholder.typicode.com/posts/1`.
27+
28+
## URL Matching
29+
30+
In addition to static urls you can also use glob patterns to match URLs, e.g. `/api/**`. See [Context Matching](https://github.com/chimurai/http-proxy-middleware#context-matching) for more details. In addition, you can provide a `filter` option that can be a custom function to determine whether a request should be proxied:
31+
32+
``` js
33+
proxyTable: {
34+
'*': {
35+
target: 'http://jsonplaceholder.typicode.com',
36+
filter: function (pathname, req) {
37+
return pathname.match('^/api') && req.method === 'GET'
38+
}
39+
}
40+
}
41+
```

docs/structure.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
│ │   ├── index.js # test build entry file
2222
│ │   └── karma.conf.js # test runner config file
2323
│ └── e2e/ # e2e tests
24-
│    ├── specs/ # test spec files
25-
│    ├── custom-assertions/ # custom assertions for e2e tests
26-
│    ├── runner.js # test runner script
27-
   └── nightwatch.conf.js # test runner config file
28-
├── .editorconfig.js # editor config
24+
   ├── specs/ # test spec files
25+
   ├── custom-assertions/ # custom assertions for e2e tests
26+
   ├── runner.js # test runner script
27+
    └── nightwatch.conf.js # test runner config file
28+
├── .editorconfig # editor config
2929
├── index.html # index.html template
3030
└── package.json # build scripts and dependencies
3131
```

meta.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ module.exports = {
4040
}
4141
]
4242
},
43+
"router": {
44+
"type": "confirm",
45+
"message": "Install vue-router?"
46+
},
4347
"unit": {
4448
"type": "confirm",
4549
"message": "Setup unit tests with Karma + Mocha?"
@@ -52,7 +56,9 @@ module.exports = {
5256
"filters": {
5357
"config/test.env.js": "unit || e2e",
5458
"test/unit/**/*": "unit",
55-
"test/e2e/**/*": "e2e"
59+
"build/webpack.test.conf.js": "unit",
60+
"test/e2e/**/*": "e2e",
61+
"src/router/**/*": "router"
5662
},
5763
"completeMessage": "To get started:\n\n cd {{destDirName}}\n npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack"
5864
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"description": "A full-featured Webpack setup with hot-reload, unit testing & css extraction.",
66
"scripts": {
77
"docs": "cd docs && gitbook serve",
8-
"deploy-docs": "bash ./deploy-docs.sh"
8+
"docs:deploy": "bash ./deploy-docs.sh"
9+
},
10+
"devDependencies": {
11+
"vue-cli": "^2.8.1"
912
}
1013
}

template/.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"presets": ["es2015", "stage-2"],
2+
"presets": [
3+
["es2015", { "modules": false }],
4+
"stage-2"
5+
],
36
"plugins": ["transform-runtime"],
47
"comments": false,
58
"env": {

template/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ npm run dev
1313

1414
# build for production with minification
1515
npm run build
16+
17+
# build for production and view the bundle analyzer report
18+
npm run build --report
1619
{{#unit}}
1720

1821
# run unit tests

template/build/build.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// https://github.com/shelljs/shelljs
22
require('./check-versions')()
3-
require('shelljs/global')
4-
env.NODE_ENV = 'production'
53

6-
var path = require('path')
7-
var config = require('../config')
4+
process.env.NODE_ENV = 'production'
5+
86
var ora = require('ora')
7+
var path = require('path')
8+
var chalk = require('chalk')
9+
var shell = require('shelljs')
910
var webpack = require('webpack')
11+
var config = require('../config')
1012
var webpackConfig = require('./webpack.prod.conf')
1113

12-
console.log(
13-
' Tip:\n' +
14-
' Built files are meant to be served over an HTTP server.\n' +
15-
' Opening index.html over file:// won\'t work.\n'
16-
)
17-
1814
var spinner = ora('building for production...')
1915
spinner.start()
2016

2117
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
22-
rm('-rf', assetsPath)
23-
mkdir('-p', assetsPath)
24-
cp('-R', 'static/*', assetsPath)
18+
shell.rm('-rf', assetsPath)
19+
shell.mkdir('-p', assetsPath)
20+
shell.config.silent = true
21+
shell.cp('-R', 'static/*', assetsPath)
22+
shell.config.silent = false
2523

2624
webpack(webpackConfig, function (err, stats) {
2725
spinner.stop()
@@ -32,5 +30,11 @@ webpack(webpackConfig, function (err, stats) {
3230
children: false,
3331
chunks: false,
3432
chunkModules: false
35-
}) + '\n')
33+
}) + '\n\n')
34+
35+
console.log(chalk.cyan(' Build complete.\n'))
36+
console.log(chalk.yellow(
37+
' Tip: built files are meant to be served over an HTTP server.\n' +
38+
' Opening index.html over file:// won\'t work.\n'
39+
))
3640
})

template/build/check-versions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var semver = require('semver')
21
var chalk = require('chalk')
2+
var semver = require('semver')
33
var packageConfig = require('../package.json')
4-
var exec = function (cmd) {
5-
return require('child_process')
6-
.execSync(cmd).toString().trim()
4+
5+
function exec (cmd) {
6+
return require('child_process').execSync(cmd).toString().trim()
77
}
88

99
var versionRequirements = [

template/build/dev-server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
require('./check-versions')()
2+
23
var config = require('../config')
3-
if (!process.env.NODE_ENV) process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
4+
if (!process.env.NODE_ENV) {
5+
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6+
}
7+
8+
var opn = require('opn')
49
var path = require('path')
510
var express = require('express')
611
var webpack = require('webpack')
7-
var opn = require('opn')
812
var proxyMiddleware = require('http-proxy-middleware')
913
var webpackConfig = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
1014
? require('./webpack.prod.conf')
1115
: {{/if_or}}require('./webpack.dev.conf')
1216

1317
// default port where dev server listens for incoming traffic
1418
var port = process.env.PORT || config.dev.port
19+
// automatically open browser, if not set will be false
20+
var autoOpenBrowser = !!config.dev.autoOpenBrowser
1521
// Define HTTP proxies to your custom API backend
1622
// https://github.com/chimurai/http-proxy-middleware
1723
var proxyTable = config.dev.proxyTable
@@ -41,7 +47,7 @@ Object.keys(proxyTable).forEach(function (context) {
4147
if (typeof options === 'string') {
4248
options = { target: options }
4349
}
44-
app.use(proxyMiddleware(context, options))
50+
app.use(proxyMiddleware(options.filter || context, options))
4551
})
4652

4753
// handle fallback for HTML5 history API
@@ -71,7 +77,7 @@ module.exports = app.listen(port, function (err) {
7177
}
7278

7379
// when env is testing, don't need open it
74-
if (process.env.NODE_ENV !== 'testing') {
80+
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
7581
opn(uri)
7682
}
7783
})

template/build/utils.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ exports.cssLoaders = function (options) {
2323
extraParamChar = '?'
2424
}
2525
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
26-
}).join('!')
26+
})
2727

2828
// Extract CSS when that option is specified
2929
// (which is the case during production build)
3030
if (options.extract) {
31-
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader)
31+
return ExtractTextPlugin.extract({
32+
loader: sourceLoader,
33+
fallback: 'vue-style-loader'
34+
})
3235
} else {
33-
return ['vue-style-loader', sourceLoader].join('!')
36+
return ['vue-style-loader', ...sourceLoader]
3437
}
3538
}
3639

@@ -54,7 +57,7 @@ exports.styleLoaders = function (options) {
5457
var loader = loaders[extension]
5558
output.push({
5659
test: new RegExp('\\.' + extension + '$'),
57-
loader: loader
60+
use: loader
5861
})
5962
}
6063
return output

template/build/vue-loader.conf.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var utils = require('./utils')
2+
var config = require('../config')
3+
var isProduction = process.env.NODE_ENV === 'production'
4+
5+
module.exports = {
6+
loaders: utils.cssLoaders({
7+
sourceMap: isProduction
8+
? config.build.productionSourceMap
9+
: config.dev.cssSourceMap,
10+
extract: isProduction
11+
}),
12+
postcss: [
13+
require('autoprefixer')({
14+
browsers: ['last 2 versions']
15+
})
16+
]
17+
}

template/build/webpack.base.conf.js

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,66 @@
11
var path = require('path')
2-
var config = require('../config')
32
var utils = require('./utils')
4-
var projectRoot = path.resolve(__dirname, '../')
3+
var config = require('../config')
4+
var vueLoaderConfig = require('./vue-loader.conf')
55

6-
var env = process.env.NODE_ENV
7-
// check env & config/index.js to decide whether to enable CSS source maps for the
8-
// various preprocessor loaders added to vue-loader at the end of this file
9-
var cssSourceMapDev = (env === 'development' && config.dev.cssSourceMap)
10-
var cssSourceMapProd = (env === 'production' && config.build.productionSourceMap)
11-
var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
6+
function resolve (dir) {
7+
return path.join(__dirname, '..', dir)
8+
}
129

1310
module.exports = {
1411
entry: {
1512
app: './src/main.ts'
1613
},
1714
output: {
1815
path: config.build.assetsRoot,
19-
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
20-
filename: '[name].js'
16+
filename: '[name].js',
17+
publicPath: process.env.NODE_ENV === 'production'
18+
? config.build.assetsPublicPath
19+
: config.dev.assetsPublicPath
2120
},
2221
resolve: {
23-
extensions: ['', '.js', '.ts', '.vue', '.json'],
24-
fallback: [path.join(__dirname, '../node_modules')],
22+
extensions: ['.js', '.ts', '.vue', '.json'],
23+
modules: [
24+
resolve('src'),
25+
resolve('node_modules')
26+
],
2527
alias: {
2628
{{#if_eq build "standalone"}}
2729
'vue$': 'vue/dist/vue.common.js',
2830
{{/if_eq}}
29-
'src': path.resolve(__dirname, '../src'),
30-
'assets': path.resolve(__dirname, '../src/assets'),
31-
'components': path.resolve(__dirname, '../src/components')
31+
'src': resolve('src'),
32+
'assets': resolve('src/assets'),
33+
'components': resolve('src/components')
3234
}
3335
},
34-
resolveLoader: {
35-
fallback: [path.join(__dirname, '../node_modules')]
36-
},
3736
module: {
38-
loaders: [
37+
rules: [
3938
{
4039
test: /\.vue$/,
41-
loader: 'vue'
40+
loader: 'vue-loader',
41+
options: vueLoaderConfig
4242
},
4343
{
4444
test: /\.ts$/,
45-
loader: 'ts'
46-
},
47-
{
48-
test: /\.json$/,
49-
loader: 'json'
45+
loader: 'ts-loader',
46+
options: {appendTsSuffixTo: [/\.vue$/]}
5047
},
5148
{
5249
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
53-
loader: 'url',
54-
query: {
50+
loader: 'url-loader',
51+
options: {
5552
limit: 10000,
5653
name: utils.assetsPath('img/[name].[hash:7].[ext]')
5754
}
5855
},
5956
{
6057
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
61-
loader: 'url',
62-
query: {
58+
loader: 'url-loader',
59+
options: {
6360
limit: 10000,
6461
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
6562
}
6663
}
6764
]
68-
},
69-
vue: {
70-
loaders: Object.assign(
71-
utils.cssLoaders({ sourceMap: useCssSourceMap }),
72-
{js: 'ts'}
73-
),
74-
postcss: [
75-
require('autoprefixer')({
76-
browsers: ['last 2 versions']
77-
})
78-
]
79-
},
80-
ts: {
81-
appendTsSuffixTo: [/\.vue$/]
8265
}
8366
}

0 commit comments

Comments
 (0)