Skip to content

Commit da27c17

Browse files
author
qkdreyer
committed
1 parent 99acbac commit da27c17

File tree

10 files changed

+134
-144
lines changed

10 files changed

+134
-144
lines changed

template/build/dev-client.js

-11
This file was deleted.

template/build/dev-server.js

-93
This file was deleted.

template/build/logo.png

6.69 KB
Loading

template/build/utils.js

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const path = require('path')
44
const config = require('../config')
55
const ExtractTextPlugin = require('extract-text-webpack-plugin')
6+
const pkg = require('../package.json')
67

78
exports.assetsPath = function (_path) {
89
const assetsSubDirectory = process.env.NODE_ENV === 'production'
@@ -71,3 +72,22 @@ exports.styleLoaders = function (options) {
7172
}
7273
return output
7374
}
75+
76+
exports.createNotifierCallback = function () {
77+
const notifier = require('node-notifier')
78+
79+
return (severity, errors) => {
80+
if (severity !== 'error') {
81+
return
82+
}
83+
const error = errors[0]
84+
85+
const filename = error.file.split('!').pop()
86+
notifier.notify({
87+
title: pkg.name,
88+
message: severity + ': ' + error.name,
89+
subtitle: filename || '',
90+
icon: path.join(__dirname, 'logo.png')
91+
})
92+
}
93+
}

template/build/webpack.base.conf.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ module.exports = {
3232
module: {
3333
rules: [
3434
{{#lint}}
35-
{
35+
...(config.dev.useEslint? [{
3636
test: /\.(js|vue)$/,
3737
loader: 'eslint-loader',
3838
enforce: 'pre',
3939
include: [resolve('src'), resolve('test')],
4040
options: {
41-
formatter: require('eslint-friendly-formatter')
41+
formatter: require('eslint-friendly-formatter'),
42+
emitWarning: !config.dev.showEslintErrorsInOverlay
4243
}
43-
},
44+
}] : []),
4445
{{/lint}}
4546
{
4647
test: /\.vue$/,

template/build/webpack.dev.conf.js

+49-8
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,39 @@ const merge = require('webpack-merge')
99
const baseWebpackConfig = require('./webpack.base.conf')
1010
const HtmlWebpackPlugin = require('html-webpack-plugin')
1111
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
12+
const portfinder = require('portfinder')
1213

13-
// add hot-reload related code to entry chunks
14-
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
15-
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
16-
})
17-
18-
module.exports = merge(baseWebpackConfig, {
14+
const devWebpackConfig = merge(baseWebpackConfig, {
1915
module: {
2016
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
2117
},
2218
// cheap-module-eval-source-map is faster for development
2319
devtool: '#cheap-module-eval-source-map',
20+
// these devServer options should be customized in /config/index.js
21+
devServer: {
22+
clientLogLevel: 'warning',
23+
hot: true,
24+
host: process.env.HOST || config.dev.host,
25+
port: process.env.PORT || config.dev.port,
26+
open: config.dev.autoOpenBrowser,
27+
overlay: config.dev.errorOverlay ? {
28+
warnings: false,
29+
errors: true,
30+
} : false,
31+
publicPath: config.dev.assetsPublicPath,
32+
proxy: config.dev.proxyTable,
33+
quiet: true, // necessary for FriendlyErrorsPlugin
34+
watchOptions: {
35+
poll: config.dev.poll,
36+
},
37+
historyApiFallback: true
38+
},
2439
plugins: [
2540
new webpack.DefinePlugin({
26-
'process.env': config.dev.env
41+
'process.env': require('../config/dev.env')
2742
}),
28-
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
2943
new webpack.HotModuleReplacementPlugin(),
44+
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
3045
new webpack.NoEmitOnErrorsPlugin(),
3146
// https://github.com/ampedandwired/html-webpack-plugin
3247
new HtmlWebpackPlugin({
@@ -39,3 +54,29 @@ module.exports = merge(baseWebpackConfig, {
3954
new FriendlyErrorsPlugin()
4055
]
4156
})
57+
58+
module.exports = new Promise((resolve, reject) => {
59+
portfinder.basePort = process.env.PORT || config.dev.port
60+
portfinder.getPort((err, port) => {
61+
if (err) {
62+
reject(err)
63+
} else {
64+
// publish the new Port, necessary for e2e tests
65+
process.env.PORT = port
66+
// add port to devServer config
67+
devWebpackConfig.devServer.port = port
68+
69+
// Add FriendlyErrorsPlugin
70+
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
71+
compilationSuccessInfo: {
72+
messages: [`Your application is running here: http://${config.dev.host}:${port}`],
73+
},
74+
onErrors: config.dev.notifyOnErrors
75+
? utils.createNotifierCallback()
76+
: undefined
77+
}))
78+
79+
resolve(devWebpackConfig)
80+
}
81+
})
82+
})

template/build/webpack.prod.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const loadMinified = require('./load-minified')
1616

1717
const env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
1818
? require('../config/test.env')
19-
: {{/if_or}}config.build.env
19+
: {{/if_or}}require('../config/prod.env')
2020

2121
const webpackConfig = merge(baseWebpackConfig, {
2222
module: {

template/config/index.js

+36-15
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,58 @@
44
const path = require('path')
55

66
module.exports = {
7+
dev: {
8+
host: 'localhost', // can be overwritten by process.env.HOST
9+
port: 8080, // can be overwritten by process.env.HOST, if port is in use, a free one will be determined
10+
11+
// Paths
12+
assetsSubDirectory: 'static',
13+
assetsPublicPath: '/',
14+
proxyTable: {},
15+
16+
// Various Dev Server settings
17+
autoOpenBrowser: false,
18+
errorOverlay: true,
19+
notifyOnErrors: true,
20+
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
21+
22+
// Use Eslint Loader?
23+
// If true, your code will be linted during bundling and
24+
// linting errors and warings will be shown in the console.
25+
useEslint: true,
26+
// If true, eslint errors and warings will also be shown in the error overlay
27+
// in the browser.
28+
showEslintErrorsInOverlay: false,
29+
30+
// CSS Sourcemaps off by default because relative paths are "buggy"
31+
// with this option, according to the CSS-Loader README
32+
// (https://github.com/webpack/css-loader#sourcemaps)
33+
// In our experience, they generally work as expected,
34+
// just be aware of this issue when enabling this option.
35+
cssSourceMap: false
36+
},
737
build: {
8-
env: require('./prod.env'),
38+
// Template for index.html
939
index: path.resolve(__dirname, '../dist/index.html'),
40+
41+
// Paths
1042
assetsRoot: path.resolve(__dirname, '../dist'),
1143
assetsSubDirectory: 'static',
1244
assetsPublicPath: '/',
45+
1346
productionSourceMap: true,
1447
// Gzip off by default as many popular static hosts such as
1548
// Surge or Netlify already gzip all static assets for you.
1649
// Before setting to `true`, make sure to:
1750
// npm install --save-dev compression-webpack-plugin
51+
1852
productionGzip: false,
1953
productionGzipExtensions: ['js', 'css'],
2054
// Run the build command with an extra argument to
2155
// View the bundle analyzer report after build finishes:
2256
// `npm run build --report`
2357
// Set to `true` or `false` to always turn it on or off
58+
2459
bundleAnalyzerReport: process.env.npm_config_report
25-
},
26-
dev: {
27-
env: require('./dev.env'),
28-
port: 8080,
29-
autoOpenBrowser: true,
30-
assetsSubDirectory: 'static',
31-
assetsPublicPath: '/',
32-
proxyTable: {},
33-
// CSS Sourcemaps off by default because relative paths are "buggy"
34-
// with this option, according to the CSS-Loader README
35-
// (https://github.com/webpack/css-loader#sourcemaps)
36-
// In our experience, they generally work as expected,
37-
// just be aware of this issue when enabling this option.
38-
cssSourceMap: false
3960
}
4061
}

template/package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"author": "{{ author }}",
66
"private": true,
77
"scripts": {
8-
"dev": "node build/dev-server.js",
9-
"start": "node build/dev-server.js",
8+
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9+
"start": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
1010
"build": "node build/build.js"{{#unit}},
1111
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}},
1212
"e2e": "node test/e2e/runner.js"{{/e2e}}{{#if_or unit e2e}},
@@ -30,7 +30,6 @@
3030
"babel-preset-stage-2": "^6.24.1",
3131
"babel-register": "^6.26.0",
3232
"chalk": "^2.1.0",
33-
"connect-history-api-fallback": "^1.4.0",
3433
"copy-webpack-plugin": "^4.1.1",
3534
"css-loader": "^0.28.7",
3635
"cssnano": "^3.10.0",
@@ -52,12 +51,10 @@
5251
{{/if_eq}}
5352
{{/lint}}
5453
"eventsource-polyfill": "^0.9.6",
55-
"express": "^4.16.2",
5654
"extract-text-webpack-plugin": "^3.0.0",
5755
"file-loader": "^1.1.5",
5856
"friendly-errors-webpack-plugin": "^1.6.1",
5957
"html-webpack-plugin": "^2.30.1",
60-
"http-proxy-middleware": "^0.17.4",
6158
"webpack-bundle-analyzer": "^2.9.0",
6259
{{#unit}}
6360
"cross-env": "^5.0.5",
@@ -78,6 +75,7 @@
7875
"babel-plugin-istanbul": "^4.1.5",
7976
"phantomjs-prebuilt": "^2.1.15",
8077
{{/unit}}
78+
"node-notifier": "^5.1.2",
8179
{{#e2e}}
8280
"chromedriver": "^2.33.1",
8381
"cross-spawn": "^5.1.0",
@@ -86,7 +84,6 @@
8684
{{/e2e}}
8785
"semver": "^5.4.1",
8886
"shelljs": "^0.7.8",
89-
"opn": "^5.1.0",
9087
"optimize-css-assets-webpack-plugin": "^3.2.0",
9188
"ora": "^1.3.0",
9289
"rimraf": "^2.6.2",
@@ -95,8 +92,7 @@
9592
"vue-style-loader": "^3.0.3",
9693
"vue-template-compiler": "^2.5.2",
9794
"webpack": "^3.7.1",
98-
"webpack-dev-middleware": "^1.12.0",
99-
"webpack-hot-middleware": "^2.19.1",
95+
"webpack-dev-server": "^2.9.1",
10096
"webpack-merge": "^4.1.0",
10197
"uglify-es": "^3.1.3"
10298
},

0 commit comments

Comments
 (0)