diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 747c159..1c4d7ff 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -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 = '/'; @@ -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: { diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index 20c83e4..4f43e44 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -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 || '/'; @@ -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: { diff --git a/utils/normalizeDefine.js b/utils/normalizeDefine.js new file mode 100644 index 0000000..9f61183 --- /dev/null +++ b/utils/normalizeDefine.js @@ -0,0 +1,7 @@ + +module.exports = function(define) { + return Object.keys(define).reduce((memo, key) => { + memo[key] = JSON.stringify(define[key]); + return memo; + }, {}); +};