如何最小化 webpack to-string-loader css? [英] How to minimize webpack to-string-loader css?

查看:58
本文介绍了如何最小化 webpack to-string-loader css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此解决方案:https://stackoverflow.com/a/45452306/417620.效果很好,但返回的 CSS 内容有注释且没有缩小.

I'm using this solution: https://stackoverflow.com/a/45452306/417620. It works great, but the CSS content that is returned has comments and is not minified.

module: [
    rules: [
      {
        test: /\.css$/,
        use: ['to-string-loader', 'css-loader']
      }
    ]
  }

我正在使用 webpack 4.我尝试使用了许多不同的加载器,但它们似乎不再适用于 webpack 4,或者它们仅在将 CSS 导出到文件时才起作用.无论如何删除CSS注释并缩小返回的CSS?

I'm using webpack 4. I've tried to use a number of different loaders, but they seem to no longer work with webpack 4 or they only work when the CSS is exported to a file. Is there anyway to remove the CSS comments and minify the CSS that is returned?

这是将 CSS 作为字符串返回的 js.从'./myCss.css'导入myCss;

Here is the js that is returning the CSS as a string. import myCss from './myCss.css';

推荐答案

你需要为你的 css-loader 提供最小化选项

You need to give minimize option true to your css-loader

module: [
    rules: [
        {
          test: /\.css$/,
          use: [
            {
              loader: "to-string-loader",
            },
            {
              loader: "css-loader",
              options: { minimize: true },
            },
          ],
       }
    ]
  }

to-string-loader 将有助于将其转换为字符串.缩小将由 css-loader 处理.

to-string-loader will help to convert it to string. Minification will be taken care by css-loader.

希望有帮助.如有任何疑问,请回复.

Hope it helps. Revert for any doubts.

这篇关于如何最小化 webpack to-string-loader css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆