我正在尝试从webpack生成一个css源图。但是,目前生成的css.map文件基本上是空的。
{"version":3,"sources":[],"names":[],"mappings":"","file":"si-styles.css","sourceRoot":""}
我知道我需要添加类似下面的内容
css-loader?sourceMap
但我不确定我是如何使用importLoaders = 1来链接它的,我目前在webpack.config.js中有这个链接。任何帮助将不胜感激。
const webpack = require('webpack');
const path = require('path');
//post css
var precss = require('precss');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var postcssImport = require('postcss-import');
module.exports = {
context: __dirname + '/frontend',
devtool: 'source-map',
entry: "./index.js",
output: {
filename: 'bundle.js',
path: path.join(__dirname, './static')
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', '!css-loader?importLoaders=1!postcss-loader')
}
]
},
plugins: [
new ExtractTextPlugin("si-styles.css")
],
// postcss: [
// precss,
// autoprefixer({ browsers: ['last 2 versions'] })
// ]
postcss: function(webpack) {
return [
postcssImport({ addDependencyTo: webpack }), // Must be first item in list
precss,
autoprefixer({ browsers: ['last 2 versions'] })
];
},
}
答案 0 :(得分:2)
我刚刚找到了一个正确的方法来做这个例子。我用过'&'链接在一起即
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', '!css-loader?sourceMap&importLoaders=1!postcss-loader')
}