Skip to content

Commit a842a4b

Browse files
committed
refine:refine build_config
1 parent be0606e commit a842a4b

File tree

8 files changed

+44
-34
lines changed

8 files changed

+44
-34
lines changed

build/build.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ var webpack = require('webpack');
99
var config = require('../config');
1010
var webpackConfig = require('./webpack.prod.conf');
1111

12-
console.log(process.env.NODE_ENV)
13-
14-
var spinner = ora('building for ' + process.env.NODE_ENV + '...')
12+
var spinner = ora('building for ' + process.env.NODE_ENV + ' of ' + process.env.env_config+ ' mode...' )
1513
spinner.start()
1614

1715

build/dev-server.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require('./check-versions')(); // 检查 Node 和 npm 版本
2+
23
var config = require('../config');
34
if (!process.env.NODE_ENV) {
45
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
@@ -28,8 +29,8 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, {
2829
});
2930

3031
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
31-
log: () => {
32-
}
32+
log: false,
33+
heartbeat: 2000
3334
});
3435

3536
// force page reload when html-webpack-plugin template changes
@@ -40,8 +41,6 @@ compiler.plugin('compilation', function (compilation) {
4041
})
4142
});
4243

43-
// compiler.apply(new DashboardPlugin());
44-
4544
// proxy api requests
4645
Object.keys(proxyTable).forEach(function (context) {
4746
var options = proxyTable[context]
@@ -67,18 +66,26 @@ app.use(staticPath, express.static('./static'));
6766

6867
var uri = 'http://localhost:' + port
6968

70-
devMiddleware.waitUntilValid(function () {
71-
console.log('> Listening at ' + uri + '\n')
72-
});
73-
74-
module.exports = app.listen(port, function (err) {
75-
if (err) {
76-
console.log(err);
77-
return
78-
}
79-
80-
// when env is testing, don't need open it
81-
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
82-
opn(uri)
83-
}
84-
});
69+
var _resolve
70+
var readyPromise = new Promise(resolve => {
71+
_resolve = resolve
72+
})
73+
74+
console.log('> Starting dev server...')
75+
devMiddleware.waitUntilValid(() => {
76+
console.log('> Listening at ' + uri + '\n')
77+
// when env is testing, don't need open it
78+
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
79+
opn(uri)
80+
}
81+
_resolve()
82+
})
83+
84+
var server = app.listen(port)
85+
86+
module.exports = {
87+
ready: readyPromise,
88+
close: () => {
89+
server.close()
90+
}
91+
}

build/webpack.base.conf.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
output: {
1515
path: config.build.assetsRoot,
1616
filename: '[name].js',
17-
publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
17+
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
1818
},
1919
resolve: {
2020
extensions: ['.js', '.vue', '.json'],
@@ -38,13 +38,13 @@ module.exports = {
3838
module: {
3939
rules: [
4040
{
41-
test: /\.(js|vue)$/,
42-
loader: 'eslint-loader',
43-
enforce: "pre",
44-
include: [resolve('src'), resolve('test')],
45-
options: {
46-
formatter: require('eslint-friendly-formatter')
47-
}
41+
test: /\.(js|vue)$/,
42+
loader: 'eslint-loader',
43+
enforce: "pre",
44+
include: [resolve('src'), resolve('test')],
45+
options: {
46+
formatter: require('eslint-friendly-formatter')
47+
}
4848
},
4949
{
5050
test: /\.vue$/,

build/webpack.prod.conf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin')
99
var ExtractTextPlugin = require('extract-text-webpack-plugin')
1010
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
1111

12-
var env = process.env.NODE_ENV === 'production' ? config.build.prodEnv : config.build.sitEnv
12+
var env = config.build[process.env.config_env+'Env']
1313

1414
function resolveApp(relativePath) {
1515
return path.resolve(relativePath);
@@ -117,9 +117,11 @@ var webpackConfig = merge(baseWebpackConfig, {
117117
}])
118118
]
119119
})
120+
120121
if (config.build.bundleAnalyzerReport) {
121122
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
122123
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
123124
}
125+
124126
module.exports = webpackConfig
125127

config/dev.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
NODE_ENV: '"development"',
3+
ENV_CONFIG: '"dev"',
34
BASE_API: '"https://api-dev"',
45
APP_ORIGIN: '"https://wallstreetcn.com"'
56
}

config/prod.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
NODE_ENV: '"production"',
3+
ENV_MODE: '"prod"',
34
BASE_API: '"https://api-prod"',
45
APP_ORIGIN: '"https://wallstreetcn.com"'
56
};

config/sit.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
NODE_ENV: '"production"',
3+
ENV_CONFIG: '"sit"',
34
BASE_API: '"https://api-sit"',
45
APP_ORIGIN: '"https://wallstreetcn.com"'
56
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"private": true,
88
"scripts": {
99
"dev": "node build/dev-server.js",
10-
"build:prod": "cross-env NODE_ENV=production node build/build.js",
11-
"build:sit": "cross-env NODE_ENV=sit node build/build.js",
12-
"build:sit-preview": "cross-env NODE_ENV=sit npm_config_preview=true npm_config_report=true node build/build.js",
10+
"build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
11+
"build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
12+
"build:sit-preview": "cross-env NODE_ENV=sit env_config=sit npm_config_preview=true npm_config_report=true node build/build.js",
1313
"lint": "eslint --ext .js,.vue src"
1414
},
1515
"dependencies": {

0 commit comments

Comments
 (0)