refine:refine build_config
This commit is contained in:
parent
be0606ebbc
commit
a842a4b451
|
@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
console.log('> Listening at ' + uri + '\n')
|
var readyPromise = new Promise(resolve => {
|
||||||
});
|
_resolve = resolve
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = app.listen(port, function (err) {
|
console.log('> Starting dev server...')
|
||||||
if (err) {
|
devMiddleware.waitUntilValid(() => {
|
||||||
console.log(err);
|
console.log('> Listening at ' + uri + '\n')
|
||||||
return
|
// when env is testing, don't need open it
|
||||||
}
|
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
|
||||||
|
opn(uri)
|
||||||
|
}
|
||||||
|
_resolve()
|
||||||
|
})
|
||||||
|
|
||||||
// when env is testing, don't need open it
|
var server = app.listen(port)
|
||||||
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
|
|
||||||
opn(uri)
|
module.exports = {
|
||||||
}
|
ready: readyPromise,
|
||||||
});
|
close: () => {
|
||||||
|
server.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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'],
|
||||||
|
@ -38,13 +38,13 @@ module.exports = {
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.(js|vue)$/,
|
test: /\.(js|vue)$/,
|
||||||
loader: 'eslint-loader',
|
loader: 'eslint-loader',
|
||||||
enforce: "pre",
|
enforce: "pre",
|
||||||
include: [resolve('src'), resolve('test')],
|
include: [resolve('src'), resolve('test')],
|
||||||
options: {
|
options: {
|
||||||
formatter: require('eslint-friendly-formatter')
|
formatter: require('eslint-friendly-formatter')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.vue$/,
|
test: /\.vue$/,
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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"'
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"'
|
||||||
};
|
};
|
||||||
|
|
|
@ -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"'
|
||||||
};
|
};
|
||||||
|
|
|
@ -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": {
|
||||||
|
|
Loading…
Reference in New Issue