我正在使用webpack2.1.0-beta.22
和web-pack-dev-server2.1.0-beta.2
设置新项目。
现在,我已经设置了一个webpack构建配置几次,所以我不是这个过程的陌生人,但是我似乎有一个奇怪的错误。当我直接运行webpack
时,我的应用程序会编译0个问题。但是,当我运行webpack-dev-server
时,它在第一次编译后失败(IE。在第一次源代码更改后)抱怨无法找到某些文件。
ERROR in ./~/css-loader!./~/postcss-loader!./src/app.css
Module build failed: (SystemJS) ENOENT: no such file or directory, open '/Users/jamie/skyrkt/bento-components/node_modules/css-loader/lib/loader'
Error: ENOENT: no such file or directory, open '/Users/jamie/skyrkt/bento-components/node_modules/css-loader/lib/loader'
at Error (native)
Error loading /Users/jamie/skyrkt/bento-components/node_modules/css-loader/lib/loader as "./lib/loader" from /Users/jamie/skyrkt/bento-components/node_modules/css-loader/index.js
@ ./src/app.css 4:14-116
@ ./src/index.js
@ multi main
有时这个错误,取决于我是否更新CSS或JS。
ERROR in ./src/index.js
Module build failed: (SystemJS) ENOENT: no such file or directory, open '/Users/jamie/skyrkt/bento-components/object-assign'
Error: ENOENT: no such file or directory, open '/Users/jamie/skyrkt/bento-components/object-assign'
at Error (native)
Error loading /Users/jamie/skyrkt/bento-components/object-assign as "object-assign" from /Users/jamie/skyrkt/bento-components/node_modules/babel-loader/index.js
@ multi main
我的整个webpack配置如下:
const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: path.join(__dirname,'src/index.js')
},
output: {
path: path.join(__dirname,'dist'),
filename: '[name].bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader', 'postcss-loader']
},
{
test: /\.(jpg|png|gif)$/,
loader: 'file-loader'
}
]
},
plugins: [
new htmlWebpackPlugin({
template: path.join(__dirname,'src/index.html')
})
],
postcss: function(webpack) {
// Irrelevant PostCSS things.
},
devServer: {
port: '8080',
host: 'localhost',
inline: true,
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
outputPath: path.join(__dirname,'dist')
}
}
我正在运行的命令是
webpack-dev-server --progress --profile --watch --content-base src/
看起来dev服务器认为它是相对于root运行的?我不是百分百肯定。
有没有人有任何想法?
更新
我可以确认使用webpack@1.13.2
和webpack-dev-server@1.15.1
而不是在我的代码中使用import
时使用require
时不会发生这种情况。
谢谢, 杰米