Skip to content

Commit 54e9328

Browse files
committed
'升级到webpack3,更新依赖版本'
1 parent 07811bf commit 54e9328

24 files changed

+651
-412
lines changed

.babelrc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"presets": [
3-
["es2015", { "modules": false }],
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
49
"stage-2"
510
],
6-
"plugins": ["transform-runtime"],
7-
"comments": false,
8-
"env": {
9-
"test": {
10-
"plugins": [ "istanbul" ]
11-
}
12-
}
11+
"plugins": ["transform-vue-jsx", "transform-runtime"]
1312
}

.postcssrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/michael-ciniawsky/postcss-load-config
2+
3+
module.exports = {
4+
"plugins": {
5+
// to edit target browsers: use "browserslist" field in package.json
6+
"postcss-import": {},
7+
"autoprefixer": {}
8+
}
9+
}

build/build.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
// https://github.com/shelljs/shelljs
1+
'use strict'
22
require('./check-versions')()
33

44
process.env.NODE_ENV = 'production'
55

6-
var ora = require('ora')
7-
var path = require('path')
8-
var chalk = require('chalk')
9-
var shell = require('shelljs')
10-
var webpack = require('webpack')
11-
var config = require('../config')
12-
var webpackConfig = require('./webpack.prod.conf')
6+
const ora = require('ora')
7+
const rm = require('rimraf')
8+
const path = require('path')
9+
const chalk = require('chalk')
10+
const webpack = require('webpack')
11+
const config = require('../config')
12+
const webpackConfig = require('./webpack.prod.conf')
1313

14-
var spinner = ora('building for production...')
14+
const spinner = ora('building for production...')
1515
spinner.start()
1616

17-
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
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
23-
24-
webpack(webpackConfig, function (err, stats) {
25-
spinner.stop()
17+
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
2618
if (err) throw err
27-
process.stdout.write(stats.toString({
28-
colors: true,
29-
modules: false,
30-
children: false,
31-
chunks: false,
32-
chunkModules: false
33-
}) + '\n\n')
19+
webpack(webpackConfig, (err, stats) => {
20+
spinner.stop()
21+
if (err) throw err
22+
process.stdout.write(stats.toString({
23+
colors: true,
24+
modules: false,
25+
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26+
chunks: false,
27+
chunkModules: false
28+
}) + '\n\n')
29+
30+
if (stats.hasErrors()) {
31+
console.log(chalk.red(' Build failed with errors.\n'))
32+
process.exit(1)
33+
}
3434

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-
))
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+
))
40+
})
4041
})

build/check-versions.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
var chalk = require('chalk')
2-
var semver = require('semver')
3-
var packageConfig = require('../package.json')
1+
'use strict'
2+
const chalk = require('chalk')
3+
const semver = require('semver')
4+
const packageConfig = require('../package.json')
5+
const shell = require('shelljs')
46

57
function exec (cmd) {
68
return require('child_process').execSync(cmd).toString().trim()
79
}
810

9-
var versionRequirements = [
11+
const versionRequirements = [
1012
{
1113
name: 'node',
1214
currentVersion: semver.clean(process.version),
1315
versionRequirement: packageConfig.engines.node
14-
},
15-
{
16+
}
17+
]
18+
19+
if (shell.which('npm')) {
20+
versionRequirements.push({
1621
name: 'npm',
1722
currentVersion: exec('npm --version'),
1823
versionRequirement: packageConfig.engines.npm
19-
}
20-
]
24+
})
25+
}
2126

2227
module.exports = function () {
23-
var warnings = []
24-
for (var i = 0; i < versionRequirements.length; i++) {
25-
var mod = versionRequirements[i]
28+
const warnings = []
29+
30+
for (let i = 0; i < versionRequirements.length; i++) {
31+
const mod = versionRequirements[i]
32+
2633
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
2734
warnings.push(mod.name + ': ' +
2835
chalk.red(mod.currentVersion) + ' should be ' +
@@ -35,10 +42,12 @@ module.exports = function () {
3542
console.log('')
3643
console.log(chalk.yellow('To use this template, you must update following to modules:'))
3744
console.log()
38-
for (var i = 0; i < warnings.length; i++) {
39-
var warning = warnings[i]
45+
46+
for (let i = 0; i < warnings.length; i++) {
47+
const warning = warnings[i]
4048
console.log(' ' + warning)
4149
}
50+
4251
console.log()
4352
process.exit(1)
4453
}

build/dev-client.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/dev-server.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

build/logo.png

6.69 KB
Loading

build/utils.js

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,101 @@
1-
var path = require('path')
2-
var config = require('../config')
3-
var ExtractTextPlugin = require('extract-text-webpack-plugin')
1+
'use strict'
2+
const path = require('path')
3+
const config = require('../config')
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5+
const packageConfig = require('../package.json')
46

57
exports.assetsPath = function (_path) {
6-
var assetsSubDirectory = process.env.NODE_ENV === 'production'
8+
const assetsSubDirectory = process.env.NODE_ENV === 'production'
79
? config.build.assetsSubDirectory
810
: config.dev.assetsSubDirectory
11+
912
return path.posix.join(assetsSubDirectory, _path)
1013
}
1114

1215
exports.cssLoaders = function (options) {
1316
options = options || {}
17+
18+
const cssLoader = {
19+
loader: 'css-loader',
20+
options: {
21+
sourceMap: options.sourceMap
22+
}
23+
}
24+
25+
const postcssLoader = {
26+
loader: 'postcss-loader',
27+
options: {
28+
sourceMap: options.sourceMap
29+
}
30+
}
31+
1432
// generate loader string to be used with extract text plugin
15-
function generateLoaders (loaders) {
16-
var sourceLoader = loaders.map(function (loader) {
17-
var extraParamChar
18-
if (/\?/.test(loader)) {
19-
loader = loader.replace(/\?/, '-loader?')
20-
extraParamChar = '&'
21-
} else {
22-
loader = loader + '-loader'
23-
extraParamChar = '?'
24-
}
25-
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
26-
}).join('!')
33+
function generateLoaders (loader, loaderOptions) {
34+
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
35+
36+
if (loader) {
37+
loaders.push({
38+
loader: loader + '-loader',
39+
options: Object.assign({}, loaderOptions, {
40+
sourceMap: options.sourceMap
41+
})
42+
})
43+
}
2744

2845
// Extract CSS when that option is specified
2946
// (which is the case during production build)
3047
if (options.extract) {
3148
return ExtractTextPlugin.extract({
32-
use: sourceLoader,
49+
use: loaders,
3350
fallback: 'vue-style-loader'
3451
})
3552
} else {
36-
return ['vue-style-loader', sourceLoader].join('!')
53+
return ['vue-style-loader'].concat(loaders)
3754
}
3855
}
3956

40-
// http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
57+
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
4158
return {
42-
css: generateLoaders(['css']),
43-
postcss: generateLoaders(['css']),
44-
less: generateLoaders(['css', 'less']),
45-
sass: generateLoaders(['css', 'sass?indentedSyntax']),
46-
scss: generateLoaders(['css', 'sass']),
47-
stylus: generateLoaders(['css', 'stylus']),
48-
styl: generateLoaders(['css', 'stylus'])
59+
css: generateLoaders(),
60+
postcss: generateLoaders(),
61+
less: generateLoaders('less'),
62+
sass: generateLoaders('sass', { indentedSyntax: true }),
63+
scss: generateLoaders('sass'),
64+
stylus: generateLoaders('stylus'),
65+
styl: generateLoaders('stylus')
4966
}
5067
}
5168

5269
// Generate loaders for standalone style files (outside of .vue)
5370
exports.styleLoaders = function (options) {
54-
var output = []
55-
var loaders = exports.cssLoaders(options)
56-
for (var extension in loaders) {
57-
var loader = loaders[extension]
71+
const output = []
72+
const loaders = exports.cssLoaders(options)
73+
74+
for (const extension in loaders) {
75+
const loader = loaders[extension]
5876
output.push({
5977
test: new RegExp('\\.' + extension + '$'),
60-
loader: loader
78+
use: loader
6179
})
6280
}
81+
6382
return output
6483
}
84+
85+
exports.createNotifierCallback = () => {
86+
const notifier = require('node-notifier')
87+
88+
return (severity, errors) => {
89+
if (severity !== 'error') return
90+
91+
const error = errors[0]
92+
const filename = error.file && error.file.split('!').pop()
93+
94+
notifier.notify({
95+
title: packageConfig.name,
96+
message: severity + ': ' + error.name,
97+
subtitle: filename || '',
98+
icon: path.join(__dirname, 'logo.png')
99+
})
100+
}
101+
}

build/vendor-manifest.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)