Skip to content

Commit 49456eb

Browse files
committed
upgrade to webpack 2
1 parent ff9c817 commit 49456eb

File tree

11 files changed

+157
-172
lines changed

11 files changed

+157
-172
lines changed

meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module.exports = {
8080
".eslintignore": "lint",
8181
"config/test.env.js": "unit || e2e",
8282
"test/unit/**/*": "unit",
83+
"build/webpack.test.conf.js": "unit",
8384
"test/e2e/**/*": "e2e"
8485
},
8586
"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"

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/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ exports.cssLoaders = function (options) {
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+
fallbackLoader: 'vue-style-loader'
34+
})
3235
} else {
3336
return ['vue-style-loader', sourceLoader].join('!')
3437
}

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+
}
Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,84 @@
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')
5+
var eslintFriendlyFormatter = require('eslint-friendly-formatter')
56

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
7+
function resolve (dir) {
8+
return path.join(__dirname, '..', dir)
9+
}
1210

1311
module.exports = {
1412
entry: {
1513
app: './src/main.js'
1614
},
1715
output: {
1816
path: config.build.assetsRoot,
19-
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
20-
filename: '[name].js'
17+
filename: '[name].js',
18+
publicPath: process.env.NODE_ENV === 'production'
19+
? config.build.assetsPublicPath
20+
: config.dev.assetsPublicPath
2121
},
2222
resolve: {
23-
extensions: ['', '.js', '.vue', '.json'],
24-
fallback: [path.join(__dirname, '../node_modules')],
23+
extensions: ['.js', '.vue', '.json'],
24+
modules: [
25+
resolve('src'),
26+
resolve('node_modules')
27+
],
2528
alias: {
2629
{{#if_eq build "standalone"}}
2730
'vue$': 'vue/dist/vue.common.js',
2831
{{/if_eq}}
29-
'src': path.resolve(__dirname, '../src'),
30-
'assets': path.resolve(__dirname, '../src/assets'),
31-
'components': path.resolve(__dirname, '../src/components')
32+
'src': resolve('src'),
33+
'assets': resolve('src/assets'),
34+
'components': resolve('src/components')
3235
}
3336
},
34-
resolveLoader: {
35-
fallback: [path.join(__dirname, '../node_modules')]
36-
},
3737
module: {
38-
{{#lint}}
39-
preLoaders: [
38+
rules: [
39+
{{#lint}}
4040
{
41-
test: /\.vue$/,
42-
loader: 'eslint',
43-
include: [
44-
path.join(projectRoot, 'src')
45-
],
46-
exclude: /node_modules/
41+
test: /\.(js|vue)$/,
42+
loader: 'eslint-loader',
43+
enforce: "pre",
44+
include: [resolve('src'), resolve('test')],
45+
exclude: /node_modules/,
46+
options: {
47+
formatter: eslintFriendlyFormatter
48+
}
4749
},
48-
{
49-
test: /\.js$/,
50-
loader: 'eslint',
51-
include: [
52-
path.join(projectRoot, 'src')
53-
],
54-
exclude: /node_modules/
55-
}
56-
],
57-
{{/lint}}
58-
loaders: [
50+
{{/lint}}
5951
{
6052
test: /\.vue$/,
61-
loader: 'vue'
53+
loader: 'vue-loader',
54+
options: vueLoaderConfig
6255
},
6356
{
6457
test: /\.js$/,
65-
loader: 'babel',
66-
include: [
67-
path.join(projectRoot, 'src')
68-
],
58+
loader: 'babel-loader',
59+
include: [resolve('src'), resolve('test')],
6960
exclude: /node_modules/
7061
},
7162
{
7263
test: /\.json$/,
73-
loader: 'json'
64+
loader: 'json-loader'
7465
},
7566
{
7667
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
77-
loader: 'url',
68+
loader: 'url-loader',
7869
query: {
7970
limit: 10000,
8071
name: utils.assetsPath('img/[name].[hash:7].[ext]')
8172
}
8273
},
8374
{
8475
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
85-
loader: 'url',
76+
loader: 'url-loader',
8677
query: {
8778
limit: 10000,
8879
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
8980
}
9081
}
9182
]
92-
},
93-
{{#lint}}
94-
eslint: {
95-
formatter: require('eslint-friendly-formatter')
96-
},
97-
{{/lint}}
98-
vue: {
99-
loaders: utils.cssLoaders({ sourceMap: useCssSourceMap }),
100-
postcss: [
101-
require('autoprefixer')({
102-
browsers: ['last 2 versions']
103-
})
104-
]
10583
}
10684
}

template/build/webpack.dev.conf.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var merge = require('webpack-merge')
44
var utils = require('./utils')
55
var baseWebpackConfig = require('./webpack.base.conf')
66
var HtmlWebpackPlugin = require('html-webpack-plugin')
7-
var FriendlyErrors = require('friendly-errors-webpack-plugin')
7+
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
88

99
// add hot-reload related code to entry chunks
1010
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
@@ -13,7 +13,7 @@ Object.keys(baseWebpackConfig.entry).forEach(function (name) {
1313

1414
module.exports = merge(baseWebpackConfig, {
1515
module: {
16-
loaders: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
16+
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
1717
},
1818
// eval-source-map is faster for development
1919
devtool: '#eval-source-map',
@@ -22,15 +22,14 @@ module.exports = merge(baseWebpackConfig, {
2222
'process.env': config.dev.env
2323
}),
2424
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
25-
new webpack.optimize.OccurrenceOrderPlugin(),
2625
new webpack.HotModuleReplacementPlugin(),
27-
new webpack.NoErrorsPlugin(),
26+
new webpack.NoEmitOnErrorsPlugin(),
2827
// https://github.com/ampedandwired/html-webpack-plugin
2928
new HtmlWebpackPlugin({
3029
filename: 'index.html',
3130
template: 'index.html',
3231
inject: true
3332
}),
34-
new FriendlyErrors()
33+
new FriendlyErrorsPlugin()
3534
]
3635
})

template/build/webpack.prod.conf.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@ var env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
1212

1313
var webpackConfig = merge(baseWebpackConfig, {
1414
module: {
15-
loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
15+
rules: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
1616
},
1717
devtool: config.build.productionSourceMap ? '#source-map' : false,
1818
output: {
1919
path: config.build.assetsRoot,
2020
filename: utils.assetsPath('js/[name].[chunkhash].js'),
2121
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
2222
},
23-
vue: {
24-
loaders: utils.cssLoaders({
25-
sourceMap: config.build.productionSourceMap,
26-
extract: true
27-
})
28-
},
2923
plugins: [
3024
// http://vuejs.github.io/vue-loader/en/workflow/production.html
3125
new webpack.DefinePlugin({
@@ -36,7 +30,6 @@ var webpackConfig = merge(baseWebpackConfig, {
3630
warnings: false
3731
}
3832
}),
39-
new webpack.optimize.OccurrenceOrderPlugin(),
4033
// extract css into its own file
4134
new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
4235
// generate dist index.html with correct asset hash for caching.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is the webpack config used for unit tests.
2+
3+
var utils = require('./utils')
4+
var webpack = require('webpack')
5+
var merge = require('webpack-merge')
6+
var baseConfig = require('./webpack.base.conf')
7+
8+
var webpackConfig = merge(baseConfig, {
9+
// use inline sourcemap for karma-sourcemap-loader
10+
module: {
11+
rules: utils.styleLoaders()
12+
},
13+
devtool: '#inline-source-map',
14+
plugins: [
15+
new webpack.DefinePlugin({
16+
'process.env': require('../config/test.env')
17+
})
18+
]
19+
})
20+
21+
// no need for app entry during tests
22+
delete webpackConfig.entry
23+
24+
module.exports = webpackConfig

0 commit comments

Comments
 (0)