Skip to content

Commit 21b4a1d

Browse files
committed
完成配置
1 parent 5bede6f commit 21b4a1d

25 files changed

+696
-599
lines changed

build/build.js

+38-34
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
'use strict'
2-
require('./check-versions')()
1+
'use strict';
2+
require('./check-versions')();
33

4-
process.env.NODE_ENV = 'production'
4+
process.env.NODE_ENV = 'production';
55

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')
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-
const spinner = ora('building for production...')
15-
spinner.start()
14+
const spinner = ora('building for production...');
15+
spinner.start();
1616

1717
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18-
if (err) throw err
19-
webpack(webpackConfig, function (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,
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)
18+
if (err) {
19+
throw err;
3320
}
21+
webpack(webpackConfig, function(err, stats) {
22+
spinner.stop();
23+
if (err) {
24+
throw err
25+
}
26+
process.stdout.write(stats.toString({
27+
colors: true,
28+
modules: false,
29+
children: false,
30+
chunks: false,
31+
chunkModules: false
32+
}) + '\n\n');
33+
34+
if (stats.hasErrors()) {
35+
console.log(chalk.red(' Build failed with errors.\n'));
36+
process.exit(1);
37+
}
3438

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-
})
41-
})
39+
console.log(chalk.cyan(' Build complete.\n'));
40+
console.log(chalk.yellow(
41+
' Tip: built files are meant to be served over an HTTP server.\n' +
42+
' Opening index.html over file:// won\'t work.\n'
43+
));
44+
});
45+
})

build/check-versions.js

+36-37
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
'use strict'
2-
const chalk = require('chalk')
3-
const semver = require('semver')
4-
const packageConfig = require('../package.json')
5-
const shell = require('shelljs')
6-
function exec (cmd) {
7-
return require('child_process').execSync(cmd).toString().trim()
1+
'use strict';
2+
const chalk = require('chalk');
3+
const semver = require('semver');
4+
const packageConfig = require('../package.json');
5+
const shell = require('shelljs');
6+
7+
function exec(cmd) {
8+
return require('child_process').execSync(cmd).toString().trim();
89
}
910

10-
const versionRequirements = [
11-
{
11+
const versionRequirements = [{
1212
name: 'node',
1313
currentVersion: semver.clean(process.version),
1414
versionRequirement: packageConfig.engines.node
15-
}
16-
]
15+
}];
1716

1817
if (shell.which('npm')) {
19-
versionRequirements.push({
20-
name: 'npm',
21-
currentVersion: exec('npm --version'),
22-
versionRequirement: packageConfig.engines.npm
23-
})
18+
versionRequirements.push({
19+
name: 'npm',
20+
currentVersion: exec('npm --version'),
21+
versionRequirement: packageConfig.engines.npm
22+
});
2423
}
2524

26-
module.exports = function () {
27-
const warnings = []
28-
for (let i = 0; i < versionRequirements.length; i++) {
29-
const mod = versionRequirements[i]
30-
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
31-
warnings.push(mod.name + ': ' +
32-
chalk.red(mod.currentVersion) + ' should be ' +
33-
chalk.green(mod.versionRequirement)
34-
)
25+
module.exports = function() {
26+
const warnings = [];
27+
for (let i = 0; i < versionRequirements.length; i++) {
28+
const mod = versionRequirements[i];
29+
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30+
warnings.push(mod.name + ': ' +
31+
chalk.red(mod.currentVersion) + ' should be ' +
32+
chalk.green(mod.versionRequirement)
33+
);
34+
}
3535
}
36-
}
3736

38-
if (warnings.length) {
39-
console.log('')
40-
console.log(chalk.yellow('To use this template, you must update following to modules:'))
41-
console.log()
42-
for (let i = 0; i < warnings.length; i++) {
43-
const warning = warnings[i]
44-
console.log(' ' + warning)
37+
if (warnings.length) {
38+
console.log('');
39+
console.log(chalk.yellow('To use this template, you must update following to modules:'));
40+
console.log();
41+
for (let i = 0; i < warnings.length; i++) {
42+
const warning = warnings[i];
43+
console.log(' ' + warning);
44+
}
45+
console.log();
46+
process.exit(1);
4547
}
46-
console.log()
47-
process.exit(1)
48-
}
49-
}
48+
}

build/dev-client.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable */
2-
'use strict'
3-
require('eventsource-polyfill')
4-
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
2+
'use strict';
3+
require('eventsource-polyfill');
4+
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true');
55

6-
hotClient.subscribe(function (event) {
7-
if (event.action === 'reload') {
8-
window.location.reload()
9-
}
10-
})
6+
hotClient.subscribe(function(event) {
7+
if (event.action === 'reload') {
8+
window.location.reload();
9+
}
10+
})

build/dev-server.js

+64-64
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
'use strict'
2-
require('./check-versions')()
1+
'use strict';
2+
require('./check-versions')();
33

4-
const config = require('../config')
4+
const config = require('../config');
55
if (!process.env.NODE_ENV) {
6-
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6+
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV);
77
}
88

9-
const opn = require('opn')
10-
const path = require('path')
11-
const express = require('express')
12-
const webpack = require('webpack')
13-
const proxyMiddleware = require('http-proxy-middleware')
14-
const webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production')
15-
? require('./webpack.prod.conf')
16-
: require('./webpack.dev.conf')
9+
const opn = require('opn');
10+
const path = require('path');
11+
const express = require('express');
12+
const webpack = require('webpack');
13+
const proxyMiddleware = require('http-proxy-middleware');
14+
const webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production') ?
15+
require('./webpack.prod.conf') :
16+
require('./webpack.dev.conf');
1717

1818
// default port where dev server listens for incoming traffic
19-
const port = process.env.PORT || config.dev.port
19+
const port = process.env.PORT || config.dev.port;
2020
// automatically open browser, if not set will be false
21-
const autoOpenBrowser = !!config.dev.autoOpenBrowser
21+
const autoOpenBrowser = !!config.dev.autoOpenBrowser;
2222
// Define HTTP proxies to your custom API backend
2323
// https://github.com/chimurai/http-proxy-middleware
24-
const proxyTable = config.dev.proxyTable
24+
const proxyTable = config.dev.proxyTable;
2525

26-
const app = express()
27-
const compiler = webpack(webpackConfig)
26+
const app = express();
27+
const compiler = webpack(webpackConfig);
2828

2929
const devMiddleware = require('webpack-dev-middleware')(compiler, {
30-
publicPath: webpackConfig.output.publicPath,
31-
quiet: true
32-
})
30+
publicPath: webpackConfig.output.publicPath,
31+
quiet: true
32+
});
3333

3434
const hotMiddleware = require('webpack-hot-middleware')(compiler, {
35-
log: false,
36-
heartbeat: 2000
37-
})
35+
log: false,
36+
heartbeat: 2000
37+
});
3838
// force page reload when html-webpack-plugin template changes
3939
// currently disabled until this is resolved:
4040
// https://github.com/jantimon/html-webpack-plugin/issues/680
@@ -47,61 +47,61 @@ const hotMiddleware = require('webpack-hot-middleware')(compiler, {
4747

4848
// enable hot-reload and state-preserving
4949
// compilation error display
50-
app.use(hotMiddleware)
50+
app.use(hotMiddleware);
5151

5252
// proxy api requests
53-
Object.keys(proxyTable).forEach(function (context) {
54-
let options = proxyTable[context]
55-
if (typeof options === 'string') {
56-
options = { target: options }
57-
}
58-
app.use(proxyMiddleware(options.filter || context, options))
53+
Object.keys(proxyTable).forEach(function(context) {
54+
let options = proxyTable[context];
55+
if (typeof options === 'string') {
56+
options = { target: options };
57+
}
58+
app.use(proxyMiddleware(options.filter || context, options));
5959
})
6060

6161
// handle fallback for HTML5 history API
62-
app.use(require('connect-history-api-fallback')())
62+
app.use(require('connect-history-api-fallback')());
6363

6464
// serve webpack bundle output
65-
app.use(devMiddleware)
65+
app.use(devMiddleware);
6666

6767
// serve pure static assets
68-
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
69-
app.use(staticPath, express.static('./static'))
68+
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory);
69+
app.use(staticPath, express.static('./static'));
7070

71-
const uri = 'http://localhost:' + port
71+
const uri = 'http://localhost:' + port;
7272

73-
var _resolve
74-
var _reject
75-
var readyPromise = new Promise((resolve, reject) => {
76-
_resolve = resolve
77-
_reject = reject
78-
})
73+
const _resolve;
74+
const _reject;
75+
const readyPromise = new Promise((resolve, reject) => {
76+
_resolve = resolve
77+
_reject = reject
78+
});
7979

80-
var server
81-
var portfinder = require('portfinder')
82-
portfinder.basePort = port
80+
let server;
81+
const portfinder = require('portfinder');
82+
portfinder.basePort = port;
8383

84-
console.log('> Starting dev server...')
84+
console.log('> Starting dev server...');
8585
devMiddleware.waitUntilValid(() => {
86-
portfinder.getPort((err, port) => {
87-
if (err) {
88-
_reject(err)
89-
}
90-
process.env.PORT = port
91-
var uri = 'http://localhost:' + port
92-
console.log('> Listening at ' + uri + '\n')
93-
// when env is testing, don't need open it
94-
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
95-
opn(uri)
96-
}
97-
server = app.listen(port)
98-
_resolve()
99-
})
86+
portfinder.getPort((err, port) => {
87+
if (err) {
88+
_reject(err);
89+
}
90+
process.env.PORT = port;
91+
const uri = 'http://localhost:' + port;
92+
console.log('> Listening at ' + uri + '\n');
93+
// when env is testing, don't need open it
94+
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
95+
opn(uri);
96+
}
97+
server = app.listen(port);
98+
_resolve();
99+
})
100100
})
101101

102102
module.exports = {
103-
ready: readyPromise,
104-
close: () => {
105-
server.close()
106-
}
107-
}
103+
ready: readyPromise,
104+
close: () => {
105+
server.close()
106+
}
107+
};

0 commit comments

Comments
 (0)