webpack的extract-text-webpack-plugin写法?

loaders: [
    {
        test: /\.less$/,
        loader: ExtractTextPlugin.extract({
            loader: [
                {
                    loader: 'css-loader',
                    query: {
                        modules: true
                    }
                },
                'less-loader'
            ]
        })
    }
]

报错

Cannot resolve module '[object Object]'

想使用query要怎么写?
直接写,知道是这样。

loader: ExtractTextPlugin.extract("style", "css?modules!less")

谢谢

写了个小demo

webpack.config.js

var path = require('path');

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

module.exports = {
    devtool: 'source-map',
    entry: {
        entry: path.join(__dirname, 'a.js'),
    },
    output: {
        filename: 'b.js',
    },
    module:{
        loaders: [
            {            
                test: /\.css$/,
                // 下面是行的,下下面是不行的
                // loader: ExtractTextPlugin.extract('css?modules'),
                loader: ExtractTextPlugin.extract({
                    fallbackLoader: "style-loader",
                    loader: { 
                        loader: "css-loader", 
                        query: {
                            sourceMap: true
                        } 
                    }
                })
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin('[name].css'),
    ],
}

a.js

require('./a.css');

console.log('a');

a.css

.test {
  background: red;
}
.test .a {
  color: red;
}
阅读 4.1k
1 个回答

你缺一个fallbackLoader,给你举个例子

loaders: [{
  test: /\.css$/,
  loader: ExtractTextPlugin.extract({
    fallbackLoader: "style-loader",
    loader: {
      loader: "css-loader",
      query: {
        sourceMap: true
      }
    }
  })
}]

https://github.com/webpack/ex...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题