refine:refine build_config

This commit is contained in:
Pan 2017-09-29 13:39:42 +08:00 committed by 花裤衩
parent be0606ebbc
commit a842a4b451
8 changed files with 42 additions and 32 deletions

View File

@ -9,9 +9,7 @@ var webpack = require('webpack');
var config = require('../config'); var config = require('../config');
var webpackConfig = require('./webpack.prod.conf'); var webpackConfig = require('./webpack.prod.conf');
console.log(process.env.NODE_ENV) var spinner = ora('building for ' + process.env.NODE_ENV + ' of ' + process.env.env_config+ ' mode...' )
var spinner = ora('building for ' + process.env.NODE_ENV + '...')
spinner.start() spinner.start()

View File

@ -1,4 +1,5 @@
require('./check-versions')(); // 检查 Node 和 npm 版本 require('./check-versions')(); // 检查 Node 和 npm 版本
var config = require('../config'); var config = require('../config');
if (!process.env.NODE_ENV) { if (!process.env.NODE_ENV) {
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
@ -28,8 +29,8 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, {
}); });
var hotMiddleware = require('webpack-hot-middleware')(compiler, { var hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: () => { log: false,
} heartbeat: 2000
}); });
// force page reload when html-webpack-plugin template changes // force page reload when html-webpack-plugin template changes
@ -40,8 +41,6 @@ compiler.plugin('compilation', function (compilation) {
}) })
}); });
// compiler.apply(new DashboardPlugin());
// proxy api requests // proxy api requests
Object.keys(proxyTable).forEach(function (context) { Object.keys(proxyTable).forEach(function (context) {
var options = proxyTable[context] var options = proxyTable[context]
@ -67,18 +66,26 @@ app.use(staticPath, express.static('./static'));
var uri = 'http://localhost:' + port var uri = 'http://localhost:' + port
devMiddleware.waitUntilValid(function () { var _resolve
var readyPromise = new Promise(resolve => {
_resolve = resolve
})
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
console.log('> Listening at ' + uri + '\n') console.log('> Listening at ' + uri + '\n')
});
module.exports = app.listen(port, function (err) {
if (err) {
console.log(err);
return
}
// when env is testing, don't need open it // when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri) opn(uri)
} }
}); _resolve()
})
var server = app.listen(port)
module.exports = {
ready: readyPromise,
close: () => {
server.close()
}
}

View File

@ -14,7 +14,7 @@ module.exports = {
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
filename: '[name].js', filename: '[name].js',
publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath : config.dev.assetsPublicPath publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
}, },
resolve: { resolve: {
extensions: ['.js', '.vue', '.json'], extensions: ['.js', '.vue', '.json'],

View File

@ -9,7 +9,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin') var ExtractTextPlugin = require('extract-text-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
var env = process.env.NODE_ENV === 'production' ? config.build.prodEnv : config.build.sitEnv var env = config.build[process.env.config_env+'Env']
function resolveApp(relativePath) { function resolveApp(relativePath) {
return path.resolve(relativePath); return path.resolve(relativePath);
@ -117,9 +117,11 @@ var webpackConfig = merge(baseWebpackConfig, {
}]) }])
] ]
}) })
if (config.build.bundleAnalyzerReport) { if (config.build.bundleAnalyzerReport) {
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin()) webpackConfig.plugins.push(new BundleAnalyzerPlugin())
} }
module.exports = webpackConfig module.exports = webpackConfig

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
NODE_ENV: '"development"', NODE_ENV: '"development"',
ENV_CONFIG: '"dev"',
BASE_API: '"https://api-dev"', BASE_API: '"https://api-dev"',
APP_ORIGIN: '"https://wallstreetcn.com"' APP_ORIGIN: '"https://wallstreetcn.com"'
} }

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
NODE_ENV: '"production"', NODE_ENV: '"production"',
ENV_MODE: '"prod"',
BASE_API: '"https://api-prod"', BASE_API: '"https://api-prod"',
APP_ORIGIN: '"https://wallstreetcn.com"' APP_ORIGIN: '"https://wallstreetcn.com"'
}; };

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
NODE_ENV: '"production"', NODE_ENV: '"production"',
ENV_CONFIG: '"sit"',
BASE_API: '"https://api-sit"', BASE_API: '"https://api-sit"',
APP_ORIGIN: '"https://wallstreetcn.com"' APP_ORIGIN: '"https://wallstreetcn.com"'
}; };

View File

@ -7,9 +7,9 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "node build/dev-server.js", "dev": "node build/dev-server.js",
"build:prod": "cross-env NODE_ENV=production node build/build.js", "build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
"build:sit": "cross-env NODE_ENV=sit node build/build.js", "build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
"build:sit-preview": "cross-env NODE_ENV=sit npm_config_preview=true npm_config_report=true node build/build.js", "build:sit-preview": "cross-env NODE_ENV=sit env_config=sit npm_config_preview=true npm_config_report=true node build/build.js",
"lint": "eslint --ext .js,.vue src" "lint": "eslint --ext .js,.vue src"
}, },
"dependencies": { "dependencies": {