Skip to content

Commit

Permalink
refactor: 开发模式时 entry 添加 hot reload 相关文件
Browse files Browse the repository at this point in the history
当 entry 为 object 类型时,为每一组都添加 hot reload 相关文件
  • Loading branch information
booxood committed May 4, 2017
1 parent 33566b4 commit 7fa3700
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions webpack/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@ const postcssPlugins = require('./postcss.config.js')

const config = _.merge({}, allConfig, allConfig.DEVELOPMENT)

const devEntries = [
require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'),
const devMiddlewareEntries = [
require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'),
]

function prependDevEntries(entry) {
if (_.isArray(entry) || _.isString(entry)) {
return _.concat(devEntries, entry)
} else if (_.isObject(entry))
{
// advanced usage, save HMR entries into a seperated chunk, pages shall include it manually.
let key = config.hmrChunkName || 'main'
entry = _.clone(entry)
entry[key] = _.concat(devEntries, entry[key] || [])
return entry
} else {
throw "invalid entry setting, check https://webpack.js.org/concepts/entry-points/ for more"
}
if (_.isArray(entry) || _.isString(entry)) {
return _.concat(devMiddlewareEntries, entry)
} else if (_.isObject(entry)) {
const newEntry = {}
Object.keys(entry).forEach(function (name) {
newEntry[name] = _.concat(devMiddlewareEntries, entry[name])
})
return newEntry
} else {
return entry
}
}

function wrapEntry(entry) {
if (_.isFunction(entry)) {
return function() {
return prependDevEntries(entry())
}
} else {
return prependDevEntries(entry)
if (_.isFunction(entry)) {
return function () {
return prependDevEntries(entry())
}
} else {
return prependDevEntries(entry)
}
}

module.exports = merge(baseWebpackConfig, {
Expand Down

0 comments on commit 7fa3700

Please sign in to comment.