使用 extract-text-webpack-plugin 的问题

Issue using extract-text-webpack-plugin

我正在尝试使用 Extract Text Webpack 插件,但我无法为已编译的 sass 文件生成新的 css 文件。

webpack.config.js

var ExtractTextPlugin = require("extract-text-webpack-plugin");


module.exports = {
    entry   :   './src/app.js',
    output  :   {
        filename    :   './dist/bundle.js'
    },
    module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader','sass-loader']
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin({
        filename : 'app.bundle.css'
    }),
  ]
}

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "dev": "webpack-dev-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^0.28.9",
    "extract-text-webpack-plugin": "^3.0.2",
    "node-sass": "^4.7.2",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.20.1",
    "webpack": "^3.11.0",
    "webpack-dev-server": "^2.11.1"
  }
}

app.js:

var css = require('../css/app.scss');

console.log("This is a test Hi from webpack !!!");
  • 我能够为编译的 sass 个文件生成一个新的 css 文件
  • 请查看回购以供参考working example

你的配置只是看起来不错,我可能是你错过了路径或忘记在 index.html 中加载 css 文件,或者你可能没有创建任何 scss 文件

live example