模块构建失败:错误:" extract-text-webpack-plugin"导入.scss文件时

时间:2018-03-30 05:31:11

标签: webpack webpack-dev-server sass-loader extract-text-plugin extracttextwebpackplugin

当我在react组件中导入.scss文件时发生了这个问题。

enter image description here

的package.json

"scripts": {
  "dev": "source ./.env && nodemon server.js"
},
"devDependencies": {
  "babel-core": "^6.26.0",
  "babel-loader": "^7.1.4",
  "babel-preset-env": "^1.6.1",
  "babel-preset-react": "^6.24.1",
  "css-loader": "^0.28.11",
  "extract-text-webpack-plugin": "^4.0.0-beta.0",
  "nodemon": "^1.17.2",
  "sass-loader": "^6.0.7",
  "style-loader": "^0.20.3",
  "webpack": "^4.4.1",
  "webpack-dev-middleware": "^3.1.0",
  "webpack-dev-server": "^3.1.1"
}

webpack.config.js

module.exports = {
  mode: 'development',
  entry: './client/app/index.js',
  output: {
    path: `${__dirname}/dist`,
    publicPath: '/',
  },
  devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        include: `${__dirname}/client`,
        loader: 'babel-loader',
      },
      {
        test: /\.scss$/,
        loaders: [
          'style-loader',
          'css-loader',
          'sass-loader'
        ]
      }
    ]
  }
};

server.js

-----

if (process.env.NODE_ENV === 'development') {
  const compiler = webpack(webpackConf);
  app.use(webpackMiddleware(compiler, {
    publicPath: webpackConf.output.publicPath,
    contentBase: './client',
    hot: true,
    stats: {
      colors: true
    }
  }));
}
----

非常有线。我没有使用extract-text-webpack-plugin。

但问题在于它。

我尝试将webpack降级到v3。但仍然失败......

有人可以帮我解决这个问题......

1 个答案:

答案 0 :(得分:1)

<强>第一即可。如果您使用sass-loader,则需要使用此configuration 作为github的推荐。

第二次rule.loaders配置错误。请参阅link

第三extract-text-webpack-plugin是来自webpack的依赖。