使用字符串替换插件在webpack dev服务器上运行,该插件执行基于替换的on a function。我发现替换的价值覆盖了我的源文件。
我的Dev服务器配置如下:
const devServer = (options) => {
return {
devServer: {
hot: true,
inline: true,
stats: 'errors-only',
host: options.host,
port: options.port,
historyApiFallback: true
},
plugins: [
new webpack.HotModuleReplacementPlugin({
multiStep: true
})
]
}
}
字符串替换插件配置为:
const constants = (data) => {
return {
module: {
loaders: [
{
test: /\.jsx?$/,
loader: StringReplacePlugin.replace({
replacements:[
{
pattern:/\`CONSTANT_(.*)\`/g,
replacement:(match,p1,offset,string)=>{
console.log('MATCH '+p1)
const keys = p1.split('.')
let current = data
keys.forEach((key)=>{
current = current[key]
})
console.log('Replacing '+p1+' with '+current)
return `'${current}'`
}
}
]
})
}
]
},
plugins: [
new StringReplacePlugin()
]
}
}
条目/ ouptut值为:
const base = {
entry: {
app: path.resolve(PATHS.app, './index.jsx')
},
output: {
path: PATHS.build,
filename: 'app.js',
publicPath: '/'
},
resolve: {
extensions: ['', '.js', '.jsx', '.json']
}
}
webpack dev服务器有没有理由在源代码上更改文件?
编辑:1 添加了JS部分:
const js = (paths) => {
const cacheDir = (process.env.CACHE_DIRECTORY ? process.env.CACHE_DIRECTORY : 'true')
return {
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: [
`babel?cacheDirectory=${cacheDir}`, // presets on .babelrc
'eslint-loader?fix'
],
include: paths
}
]
}
}
}
编辑2 原因似乎是eslint-loader?修复,当删除时,实现了相应的行为。现在我正在寻求如何防止
答案 0 :(得分:0)
在每次更改之前放置eslint-loader?修复都会阻止它。