Skip to content

Commit 881952a

Browse files
committed
upgrade to webpack rc
1 parent a6723d1 commit 881952a

File tree

9 files changed

+83
-46
lines changed

9 files changed

+83
-46
lines changed

template/build/server.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
'use strict'
22
const fs = require('fs')
33
const path = require('path')
4+
const chalk = require('chalk')
45
const express = require('express')
56
const webpack = require('webpack')
6-
const fse = require('fs-extra')
77
const webpackConfig = require('./webpack.dev')
88
const config = require('./config')
99

1010
const app = express()
1111

1212
const port = config.port
1313
webpackConfig.entry.client = [
14-
`webpack-hot-middleware/client{{#electron}}?path=http://localhost:${port}/__webpack_hmr{{/electron}}`,
14+
`webpack-hot-middleware/client?reload=true{{#electron}}&path=http://localhost:${port}/__webpack_hmr{{/electron}}`,
1515
webpackConfig.entry.client
1616
]
1717
{{#electron}}
1818

1919
webpackConfig.output.publicPath = `http://localhost:${port}/assets/`
2020
{{/electron}}
2121

22-
const compiler = webpack(webpackConfig)
22+
let compiler
23+
24+
try {
25+
compiler = webpack(webpackConfig)
26+
} catch (err) {
27+
console.log(err.message)
28+
process.exit(1)
29+
}
2330

2431
const devMiddleWare = require('webpack-dev-middleware')(compiler, {
2532
publicPath: webpackConfig.output.publicPath,
@@ -28,7 +35,9 @@ const devMiddleWare = require('webpack-dev-middleware')(compiler, {
2835
modules: false,
2936
children: false,
3037
chunks: false,
31-
chunkModules: false
38+
chunkModules: false,
39+
hash: false,
40+
timings: false
3241
}
3342
})
3443
app.use(devMiddleWare)
@@ -37,13 +46,10 @@ app.use(require('webpack-hot-middleware')(compiler))
3746
const mfs = devMiddleWare.fileSystem
3847
const file = path.join(webpackConfig.output.path, 'index.html')
3948

40-
devMiddleWare.waitUntilValid(() => {
41-
const html = mfs.readFileSync(file)
42-
fse.ensureDirSync(path.dirname(file))
43-
fs.writeFile(file, html, 'utf8', err => {
44-
if (err) console.log(err)
45-
})
46-
})
49+
console.log(`\n > VuePack is running at ${chalk.yellow(`http://localhost:${port}`)}\n`)
50+
51+
52+
devMiddleWare.waitUntilValid()
4753

4854
app.get('*', (req, res) => {
4955
devMiddleWare.waitUntilValid(() => {

template/build/utils.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22
const path = require('path')
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
34
const config = require('./config')
45

56
const _ = module.exports = {}
@@ -19,3 +20,42 @@ _.outputIndexPath = config.electron ?
1920
_.target = config.electron ?
2021
'electron-renderer' :
2122
'web'
23+
24+
// https://github.com/egoist/vbuild/blob/master/lib/vue-loaders.js
25+
_.loadersOptions = () => {
26+
const isProd = process.env.NODE_ENV === 'production'
27+
28+
function generateLoader(langs) {
29+
langs.unshift('css-loader?sourceMap&-autoprefixer')
30+
if (!isProd) {
31+
return ['vue-style-loader'].concat(langs).join('!')
32+
}
33+
return ExtractTextPlugin.extract({
34+
fallbackLoader: 'vue-style-loader',
35+
loader: langs.join('!')
36+
})
37+
}
38+
39+
return {
40+
minimize: isProd,
41+
options: {
42+
// css-loader relies on context
43+
context: process.cwd(),
44+
// postcss plugins apply to .css files
45+
postcss: config.postcss,
46+
babel: config.babel,
47+
vue: {
48+
// postcss plugins apply to css in .vue files
49+
postcss: config.postcss,
50+
loaders: {
51+
css: generateLoader([]),
52+
sass: generateLoader(['sass-loader?indentedSyntax']),
53+
scss: generateLoader(['sass-loader']),
54+
less: generateLoader(['less-loader']),
55+
stylus: generateLoader(['stylus-loader']),
56+
js: 'babel-loader'
57+
}
58+
}
59+
}
60+
}
61+
}

template/build/webpack.base.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ module.exports = {
1414
filename: '[name].js',
1515
publicPath: '/'
1616
},
17+
performance: {
18+
hints: process.env.NODE_ENV === 'production' ? 'warning' : false
19+
},
1720
resolve: {
18-
extensions: ['', '.js', '.vue', '.css', '.json'],
21+
extensions: ['.js', '.vue', '.css', '.json'],
1922
alias: {
2023
root: path.join(__dirname, '../client'),
2124
components: path.join(__dirname, '../client/components')
@@ -25,38 +28,33 @@ module.exports = {
2528
loaders: [
2629
{
2730
test: /\.vue$/,
28-
loaders: ['vue']
31+
loaders: ['vue-loader']
2932
},
3033
{
3134
test: /\.js$/,
32-
loaders: ['babel'],
35+
loaders: ['babel-loader'],
3336
exclude: [/node_modules/]
3437
},
3538
{
3639
test: /\.es6$/,
37-
loaders: ['babel']
40+
loaders: ['babel-loader']
3841
},
3942
{
4043
test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
41-
loader: 'file',
44+
loader: 'file-loader',
4245
query: {
4346
name: 'static/media/[name].[hash:8].[ext]'
4447
}
4548
}
4649
]
4750
},
48-
babel: config.babel,
49-
postcss: config.postcss,
50-
vue: {
51-
loaders: {},
52-
postcss: config.postcss
53-
},
5451
plugins: [
5552
new HtmlWebpackPlugin({
5653
title: config.title,
5754
template: __dirname + '/index.html',
5855
filename: _.outputIndexPath
59-
})
56+
}),
57+
new webpack.LoaderOptionsPlugin(_.loadersOptions())
6058
],
6159
target: _.target
6260
}

template/build/webpack.dev.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict'
2+
process.env.NODE_ENV = 'development'
3+
24
const webpack = require('webpack')
35
const base = require('./webpack.base')
46
const _ = require('./utils')
@@ -16,7 +18,7 @@ base.plugins.push(
1618
base.module.loaders.push(
1719
{
1820
test: /\.css$/,
19-
loader: `style-loader!${_.cssLoader}!postcss-loader`
21+
loaders: ['style-loader', _.cssLoader, 'postcss-loader']
2022
}
2123
)
2224

template/build/webpack.prod.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict'
2+
process.env.NODE_ENV = 'production'
3+
24
const exec = require('child_process').execSync
35
const webpack = require('webpack')
46
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5-
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
7+
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
68
const base = require('./webpack.base')
79
const pkg = require('../package')
810
const _ = require('./utils')
@@ -24,14 +26,11 @@ base.entry.vendor = config.vendor
2426
base.output.filename = '[name].[chunkhash:8].js'
2527
// add webpack plugins
2628
base.plugins.push(
27-
new ProgressBarPlugin(),
29+
new ProgressPlugin(),
2830
new ExtractTextPlugin('styles.[contenthash:8].css'),
2931
new webpack.DefinePlugin({
3032
'process.env.NODE_ENV': JSON.stringify('production')
3133
}),
32-
new webpack.LoaderOptionsPlugin({
33-
minimize: true
34-
}),
3534
new webpack.optimize.UglifyJsPlugin({
3635
sourceMap: true,
3736
compress: {
@@ -57,10 +56,4 @@ base.module.loaders.push({
5756
})
5857
})
5958

60-
// extract css in single-file components
61-
base.vue.loaders.css = ExtractTextPlugin.extract({
62-
loader: 'css-loader?-autoprefixer',
63-
fallbackLoader: 'vue-style-loader'
64-
})
65-
6659
module.exports = base

template/client/components/App.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ body {
1717
}
1818
.page {
1919
text-align: center;
20-
}
21-
code {
22-
background-color: #f0f0f0;
23-
padding: 3px 5px;
24-
border-radius: 2px;
20+
/* nesting for the need to test postcss */
21+
code {
22+
background-color: #f0f0f0;
23+
padding: 3px 5px;
24+
border-radius: 2px;
25+
}
2526
}
2627
</style>

template/client/components/Counter.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default {
2121

2222
<style>
2323
.counter {
24-
cursor: pointer;
2524
margin: 100px auto;
2625
border-radius: 3px;
2726
width: 200px;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.counter {
2-
cursor: pointer;
32
margin: 100px auto;
43
border-radius: 3px;
54
width: 200px;
@@ -9,4 +8,4 @@
98
font-size: 5rem;
109
background-color: #f0f0f0;
1110
user-select: none;
12-
}
11+
}

template/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"babel-plugin-transform-vue-jsx": "^3.1.0",
3030
"babel-preset-es2015": "^6.14.0",
3131
"babel-preset-stage-1": "^6.13.0",
32+
"chalk": "^1.1.3",
3233
"css-loader": "^0.23.1",
3334
"cross-env": "^2.0.0",
3435
{{#electron}}
@@ -41,16 +42,14 @@
4142
{{/eslint}}
4243
"express": "^4.14.0",
4344
"extract-text-webpack-plugin": "^2.0.0-beta.3",
44-
"fs-extra": "^0.30.0",
4545
"file-loader": "^0.9.0",
4646
"html-webpack-plugin": "^2.22.0",
4747
"postcss-loader": "^0.9.1",
4848
"postcss-nested": "^1.0.0",
49-
"progress-bar-webpack-plugin": "^1.9.0",
5049
"style-loader": "^0.13.1",
5150
"vue-loader": "^10.0.2",
5251
"vue-template-compiler": "^2.1.3",
53-
"webpack": "2.1.0-beta.22",
52+
"webpack": "2.2.0-rc.1",
5453
"webpack-dev-middleware": "^1.8.1",
5554
"webpack-hot-middleware": "^2.12.2"
5655
}

0 commit comments

Comments
 (0)