迁移到Webpack,找不到模块(无法解析'./style.css')

时间:2018-04-19 00:43:00

标签: webpack webpack-dev-server webpack-4

我正在将我们的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路径,该路径甚至包括硬盘而dev服务器没有抛出错误,所以它一定是路径问题?

我可以看到[名称] .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'
        ]
      }
    ]
  }
};

0 个答案:

没有答案