Skip to content

Commit 2e3fb8e

Browse files
committed
change some config
1 parent 16778c4 commit 2e3fb8e

File tree

10 files changed

+56
-43
lines changed

10 files changed

+56
-43
lines changed

template/build/base-config/configs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ module.exports = {
22
development: {
33
performance: {
44
hints: false,
5-
maxAssetSize: 2000000
5+
maxAssetSize: 2000000 // 2.5M
66
}
77
},
88
production: {
99
performance: {
1010
hints: 'error',
11-
maxEntrypointSize: 1500000
11+
maxEntrypointSize: 1500000 // 1.5M
1212
},
1313
stats: {
1414
chunkModules: false,

template/build/base-config/environment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module.exports = {
1111
NODE_ENV: JSON.stringify(NODE_ENV)
1212
},
1313
env: NODE_ENV,
14-
isDev: NODE_ENV === 'development',
15-
isProd: NODE_ENV === 'production',
16-
isTest: NODE_ENV === 'test',
14+
__DEV__: NODE_ENV === 'development',
15+
__PRO__: NODE_ENV === 'production',
16+
__TEST__: NODE_ENV === 'test',
1717
config: Object.assign(envConfigs.defaults, envConfigs[NODE_ENV] || {})
1818
};

template/build/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const app = express();
99
app.use(require('compression')());
1010

1111
// Apply Webpack HMR Middleware
12-
if (env.isDev) {
12+
if (env.__DEV__) {
1313
const webpack = require('webpack');
1414
const webpackConfig = require('./webpack-config');
1515
const compiler = webpack(webpackConfig);
16-
debug('Apply webpack dev and HMR middleware(开启开发环境插件 webpack-dev 和 HRM 中间件)');
16+
debug('Apply webpack dev and HMR middleware');
1717
app.use(require('webpack-dev-middleware')(compiler, {
1818
publicPath: webpackConfig.output.publicPath,
1919
contentBase: paths.src(),
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
/**
2+
* https://docs.npmjs.com/files/package.json#name,
3+
* this alias name have to not support package name;
4+
*/
15
module.exports = paths => ({
2-
UTILS: paths.src('utils'),
3-
COMPONENTS: paths.src('components'),
4-
CONTAINERS: paths.src('containers'),
5-
STYLES: paths.src('styles'),
6-
REDUCERS: paths.src('reducers'),
7-
LAYOUTS: paths.src('layouts')
6+
'$utils': paths.src('utils'),
7+
'$components': paths.src('components'),
8+
'$containers': paths.src('containers'),
9+
'$styles': paths.src('styles'),
10+
'$reducers': paths.src('reducers'),
11+
'$layouts': paths.src('layouts')
812
});

template/build/webpack-config/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const debug = require('debug')('app:webpack:base');
22
const env = require('../base-config/environment');
33

4-
const isDev = env.isDev;
4+
const isDev = env.__DEV__;
55
const envConfig = env.config;
66

77
const pkg = require('../../package.json');
@@ -25,7 +25,7 @@ module.exports = (paths) => {
2525
app: App,
2626
vendors: Vendors
2727
},
28-
devtool: isDev ? 'eval' : 'cheap-source-map',
28+
devtool: isDev ? 'eval' : false,
2929
output: {
3030
filename: '[name].[hash:8].js',
3131
path: paths.dist(),

template/build/webpack-config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const base = require('./base')(paths);
66
const loaders = require('./loaders')();
77
const plugins = require('./plugins')(paths);
88

9-
debug('Creating configuration.(创建配置)');
9+
debug('Creating configuration.');
1010
module.exports = Object.assign({
1111
plugins,
1212
resolve: {

template/build/webpack-config/loaders.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const debug = require('debug')('app:webpack:loaders');
22
const env = require('../base-config/environment');
33
const ExtractTextPlugin = require('extract-text-webpack-plugin');
44

5-
const isDev = env.isDev;
6-
const isProd = env.isProd;
5+
const isDev = env.__DEV__;
6+
const isProd = env.__PRO__;
77
module.exports = () => {
88
const rules = [{
99
test: /\.(js|jsx)$/,
@@ -13,25 +13,34 @@ module.exports = () => {
1313
test: /\.json$/,
1414
use: [{ loader: 'json-loader' }]
1515
}, {
16-
test: /\.(css|less)$/,
17-
use: [
18-
{
19-
loader: 'style-loader'
20-
}, {
21-
loader: 'css-loader',
22-
options: {
23-
minimize: isProd,
24-
sourceMap: !isProd
25-
}
26-
}, {
27-
loader: 'postcss-loader'
28-
}, {
29-
loader: 'less-loader',
30-
options: {
31-
sourceMap: !isProd
32-
}
16+
test: /\.css$/,
17+
use: [{
18+
loader: 'style-loader'
19+
}, {
20+
loader: 'css-loader',
21+
options: {
22+
minimize: isProd
23+
}
24+
}, {
25+
loader: 'postcss-loader'
26+
}]
27+
}, {
28+
test: /\.less$/,
29+
use: [{
30+
loader: 'style-loader'
31+
}, {
32+
loader: 'css-loader',
33+
options: {
34+
minimize: isProd
3335
}
34-
]
36+
}, {
37+
loader: 'postcss-loader'
38+
}, {
39+
loader: 'less-loader',
40+
options: {
41+
sourceMap: !isProd
42+
}
43+
}]
3544
}, {
3645
test: /\.(png|jpg)$/,
3746
use: [{

template/build/webpack-config/plugins.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
44
const ExtractTextPlugin = require('extract-text-webpack-plugin');
55
const env = require('../base-config/environment');
66

7-
const isDev = env.isDev;
8-
const isProd = env.isProd;
7+
const isDev = env.__DEV__;
8+
const isProd = env.__PRO__;
99

1010
module.exports = (paths) => {
1111
const plugins = [
@@ -30,13 +30,13 @@ module.exports = (paths) => {
3030
})
3131
];
3232
if (isDev) {
33-
debug('Enable HMR,noErrors for development(开启开发环境插件)');
33+
debug('Enable HMR,noErrors for development');
3434
plugins.push(
3535
new webpack.HotModuleReplacementPlugin(),
3636
new webpack.NoEmitOnErrorsPlugin() // 报错时不退出webpack进程
3737
);
3838
} else {
39-
debug('Apply ExtractTextPlugin.(非开发环境开启ExtractTextPlugin)');
39+
debug('Apply ExtractTextPlugin.');
4040
plugins.push(
4141
new ExtractTextPlugin({
4242
filename: '[name].[hash:8].css',
@@ -45,7 +45,7 @@ module.exports = (paths) => {
4545
);
4646
}
4747
if (isProd) {
48-
debug('Enable OccurenceOrder,UglifyJs for production(开启生产环境打包插件)');
48+
debug('Enable OccurenceOrder,UglifyJs for production.');
4949
plugins.push(
5050
new webpack.optimize.OccurrenceOrderPlugin(), // 根据模块使用情况 排序模块序号
5151
new webpack.optimize.UglifyJsPlugin({

template/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const render = () => {
1717
MOUNT_NODE
1818
);
1919
};
20-
if (isDev && module.hot) {
20+
if (__DEV__ && module.hot) {
2121
module.hot.accept('./routes/index', () => {
2222
ReactDOM.unmountComponentAtNode(MOUNT_NODE);
2323
render();

template/src/store/createStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (initialState = {}) => {
1010
const enhancers = [];
1111
const globalReducerMaps = [];
1212

13-
if (isDev) {
13+
if (__DEV__) {
1414
const devToolsExtension = window.devToolsExtension;
1515
if (typeof devToolsExtension === 'function') {
1616
enhancers.push(devToolsExtension());

0 commit comments

Comments
 (0)