使用webpack-dev-server编译我的资产时,我遇到了性能问题。出于某种原因,webpack-dev-server在重建时非常缓慢。 webpack -watch的速度提高了约90%。
我的webpack配置:
var webpackConfig = {
entry: {
router: [
'webpack-dev-server/client?https://localhost:3000',
'webpack/hot/only-dev-server',
'<%= pkg.main %>'
]
},
output: {
filename: './js/v2/bundle.js',
publicPath: 'https://localhost:3000/'
},
module: {
loaders: moduleLoaders
},
resolve: {
root: jsFilePaths,
extensions: ['', '.js', '.jsx', '.css'],
alias: webpackAlias,
fallback: ["./node_modules"]
},
resolveLoader: {
root: path.join(__dirname, "node_modules")
},
devtool: 'eval-source-map',
watch: true,
profile: true,
json: true,
cache: true,
keepAlive: true,
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.HotModuleReplacementPlugin()
]
};
我的webpack-dev-server配置(使用grunt):
"webpack-dev-server": {
options: {
webpack: webpackConfig,
publicPath: webpackConfig.output.publicPath,
port: 3000,
https:true,
host: "localhost",
contentBase: "https://localhost",
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' }
},
start: {
keepAlive: true
}
看起来webpack-dev-server没有正确使用它的缓存或其他东西。任何想法都会对他有所帮助。
答案 0 :(得分:4)
问题在于解决:root。
原始jsFilePaths:
var jsFilePaths = [
'js/v2/components',
'js/v2/components/shared'
];
新jsFilePaths:
var jsFilePaths = [
__dirname + path.sep + 'js\\v2\\components',
__dirname + path.sep + 'js\\v2\\components\\shared'
];
显然只有在Windows上才需要这样做。如果路径是unix格式,Webpack似乎并不依赖于依赖项。