我正在将我们的 AngularJS 项目从 Gulp 迁移到 Webpack。我正在按照文档进行操作,但我不断收到此错误:
ERROR in ./src/js/index.js
Module not found: Error: Can't resolve './style.css' in '/Users/username/Development/yd-front-end/src/js'
@ ./src/js/index.js 1:0-21
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/js/index.js
ℹ 「wdm」: Failed to compile.
^C
这是 index.js 文件:
import './style.css';
const stuff = '2';
console.log(stuff);
我把上面的style.css路径换成了连硬盘都包含在内的绝对路径,开发服务器也没有报错,那一定是路径问题吧?
我可以看到 [name].bundle.js 导出就好了。
const path = require("path");
module.exports = {
mode: "development",
entry: "./src/js/index.js",
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist/js")
},
devtool: "inline-source-map",
devServer: {
contentBase: "./src"
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
}
};