[英]How can I configure webpack 3.5.4 to only create source maps for JS, and skip CSS?
I've been trying to figure out how to skip the CSS source maps in production, because I only need JS. 我一直在尝试找出如何在生产中跳过CSS源映射,因为我只需要JS。 Is there a way to do this?
有没有办法做到这一点?
I can just delete the *.css.map
files later, but I think the build would be faster if I can skip them. 我可以稍后再删除
*.css.map
文件,但我认为如果可以跳过它们,构建速度会更快。
The following is a snippet from my webpack config. 以下是我的webpack配置中的片段。 You can simply set the value of
sourceMap
option to false
: 您可以简单地将
sourceMap
选项的值设置为false
:
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: false,
importLoaders: 2,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'postcss-loader',
options: {
sourceMap: false,
},
},
],
},
You can also use suppress-chunks-webpack-plugin to remove the .css.map
files, because webpack still writes them even if they are empty. 您还可以使用prevent-chunks-webpack-plugin删除
.css.map
文件,因为即使它们为空,webpack仍会写入它们。
Add a new plugin to your config: 将新插件添加到您的配置中:
// Skip empty CSS source maps
new SuppressChunksPlugin([
{ name: 'your-entry', match: /\.css\.map$/ },
]),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.