Webpack没有将scss编译为css

时间:2018-01-22 18:34:19

标签: css webpack sass

我正在使用webpack,babel和Sass构建应用程序。一切正常但sass文件没有编译css文件,即使它没有抛出任何错误。 与此相关的我的包是:

“webpack”:“^ 3.10.0”,

“css-loader”:“^ 0.28.9”,

“extract-text-webpack-plugin”:“^ 3.0.2”,

“glob-all”:“^ 3.1.0”,

“node-sass”:“^ 4.7.2”,

“purify-css”:“^ 1.2.5”,

“purifycss-webpack”:“^ 0.7.0”,

“sass-loader”:“^ 6.0.6”

webpack.config.js

var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const glob = require('glob-all');
var PurifyCSSPlugin= require('purifycss-webpack'); 

module.exports = {
  entry: './src/js/index.js',
  output: {
    path: __dirname,
    filename: 'dist/js/bundle.js'
  },
  watch: true,
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env', 'stage-3'],
          }
        }
      },
      {
        test:/\.css$/,
        use: ExtractTextPlugin.extract({
          use: [ 
            {
              loader: 'css-loader',
              options: {
                url: false
              }
            }
          ]
        })
      },
      {
        test:/\.scss$/,
        use: ExtractTextPlugin.extract({
          use: [ 
            {
              loader: 'css-loader',
              options: {
                url: false
              }
            },
            'sass-loader'
          ]
        })
      }
    ]
  },

  plugins: [
    new ExtractTextPlugin({
      filename: './dist/css/styles.css'
    }),
    new PurifyCSSPlugin({
      paths: glob.sync([
        path.join(__dirname, 'dist/index.html'),
        path.join(__dirname, 'src/js/*.js')
      ])
    })
  ]
}

文件目录: This is my project Files Directory

1 个答案:

答案 0 :(得分:0)

test:/\.scss$/,
    use: ExtractTextPlugin.extract({
      use: [ 
        {
          loader: ['style-loader', 'css-loader', 'sass-loader']
          options: {
            url: false
          }
        },
      ]
    })