在Webpack 2中创建css文件

时间:2018-03-12 13:56:09

标签: webpack

我正在处理webpack-config,我想把我的sass文件导出为i.cc文件到“static / css”,就像我用js一样。我不能让它工作。这就是我的webpack的样子:

const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
const config = {
devtool: '#eval-source-map',
entry: './src/js/index.js',
output: {
    filename: isProd ? '[name].[chunkhash].js' : '[name].js',
    path: path.resolve(__dirname, 'static/js')
},
module: {
    rules: [{
        test: /\.js$/,
        loader: 'buble-loader',
        exclude: /node_modules/,
        options: {
            objectAssign: 'Object.assign'
        }
    }, 
    {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract(['css-loader', 'sass-
        loader'])
    }]
}
}

if (isProd) {
    config.devtool = '#source-map'
    config.plugins.push(
        new webpack.LoaderOptionsPlugin({
            minimize: true
        }),
        new webpack.optimize.UglifyJsPlugin({
            sourceMap: true
        })
    )
}

module.exports = config