【问题标题】:How can I compile each scss file into its own folder without merging them into one?如何将每个 scss 文件编译到自己的文件夹中而不将它们合并到一个文件夹中?
【发布时间】:2019-12-19 10:48:13
【问题描述】:

我有 Angular 组件。每个组件在其文件夹中都有一个 CSS 文件。我使用 SCSS 预处理器,所以我需要让 Webpack 只编译 SCSS 文件而不将它们合并为一个。例如


Before:
src
|-app
  |_component1
  | component1.html
  | component1.ts
  | component1.scss
  |
  |_component2
  | component2.html
  | component2.ts
  | component2.scss


After:
src
|-app
  |_component1
  | component1.html
  | component1.ts
  | component1.scss
  | component1.css
  |
  |_component2
  | component2.html
  | component2.ts
  | component2.scss
  |  component2.css

【问题讨论】:

    标签: javascript css node.js webpack sass


    【解决方案1】:

    你可以通过在你的 webpack 中进行配置来实现这一点

    const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    {
    ...
      plugins: [
        ...
        new MiniCssExtractPlugin({
          filename: "[name].css",
          chunkFilename: "[id].css"
        })
        ...
      ],
      module: {
        rules: [
           ...
          {
            test: /\.(css|scss)$/,
            use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
          }
          ...
        ]
      }
    ...
    };
    
    

    【讨论】:

      【解决方案2】:

      您不必在 webpack 中执行此操作,我什至不知道这是否可能。 安装node-sass,然后添加到package.js

      "scripts": {
        "test": "blah blah blah",
        "sass": "node-sass ./src/app/ --output ./src/app/ --recursive false -w"
      }
      

      阅读更多如何使用它node-sass

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-27
        • 2016-05-08
        • 2019-05-15
        • 1970-01-01
        • 1970-01-01
        • 2020-07-01
        • 2016-05-01
        • 2020-09-05
        相关资源
        最近更新 更多