Skip to content

Commit

Permalink
support define config, Close #8
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 29, 2016
1 parent 222bc4a commit 780cf74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getEntry = require('../utils/getEntry');
const getTheme = require('../utils/getTheme');
const getConfig = require('../utils/getConfig');
const getCSSLoaders = require('../utils/getCSSLoaders');
const normalizeDefine = require('../utils/normalizeDefine');

const config = getConfig();
const publicPath = '/';
Expand Down Expand Up @@ -136,6 +137,9 @@ module.exports = {
).concat(
!config.multipage ? [] :
new webpack.optimize.CommonsChunkPlugin('common', 'common.js')
).concat(
!config.define ? [] :
new webpack.DefinePlugin(normalizeDefine(config.define))
),
externals: config.externals,
node: {
Expand Down
4 changes: 4 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getEntry = require('../utils/getEntry');
const getTheme = require('../utils/getTheme');
const getConfig = require('../utils/getConfig');
const getCSSLoaders = require('../utils/getCSSLoaders');
const normalizeDefine = require('../utils/normalizeDefine');

const config = getConfig();
const publicPath = config.publicPath || '/';
Expand Down Expand Up @@ -166,6 +167,9 @@ module.exports = function(args, appBuild) {
).concat(
!config.multipage ? [] :
new webpack.optimize.CommonsChunkPlugin('common', 'common.js')
).concat(
!config.define ? [] :
new webpack.DefinePlugin(normalizeDefine(config.define))
),
externals: config.externals,
node: {
Expand Down
7 changes: 7 additions & 0 deletions utils/normalizeDefine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

module.exports = function(define) {
return Object.keys(define).reduce((memo, key) => {
memo[key] = JSON.stringify(define[key]);
return memo;
}, {});
};

0 comments on commit 780cf74

Please sign in to comment.