CSS sourcemap 使用 Extract Text Plugin /CSS-loader Webpack
CSS sourcemap using Extract Text Plugin /CSS-loader Webpack
我正在尝试从 webpack 生成一个 css sourcemap。但是,目前生成的 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'] })
];
},
}
我刚刚找到了一个正确方法的示例。我用'&'链接在一起,即
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', '!css-loader?sourceMap&importLoaders=1!postcss-loader')
}
我正在尝试从 webpack 生成一个 css sourcemap。但是,目前生成的 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'] })
];
},
}
我刚刚找到了一个正确方法的示例。我用'&'链接在一起,即
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', '!css-loader?sourceMap&importLoaders=1!postcss-loader')
}