【问题标题】:Combining Multiple SASS files into one SASS file将多个 SASS 文件合并为一个 SASS 文件
【发布时间】:2015-01-22 10:09:44
【问题描述】:

有谁知道是否有办法将多个 SASS/SCSS 文件合并到一个 SASS/SCSS 文件中。我的意思是“合并为一个 SASS/SCSS”,不是 合并为一个 CSS 文件。

例如,我有 3 个 scss 文件:

  • app.scss
  • base.scss
  • layout.scss

app.scss 文件包含 2 个对 base.scsslayout.scss 的导入。

我希望能够生成 1 个基本上连接文件并且不处理 sass 的 SCSS 文件。

搜索起来相当困难,因为返回的所有内容都与合并到 CSS 中有关。

我为什么要这样做?基本上,我想在 codepen(其他在线代码编辑器)中轻松引用一组 SCSS 文件。

谢谢

【问题讨论】:

标签: sass


【解决方案1】:

我通过掩码分析所有文件,找到里面的所有导入并连接到一个文件中。所以我不需要一个入口点

npm install -D bundle-scss

"script": {
  "postbuild": "npm run themes",
  "themes": "bundle-scss -m \"./src/**/*.theme.scss\" -d \"./dist/themes.scss\""
}

【讨论】:

    【解决方案2】:

    您可以针对 javascript 进行修改。将它保存在打字稿中,因为我目前正在自己​​解决这个问题(角度 6 库),并遇到了这个问题。

    根据文档,角度材料使用此实现。

    import * as path from 'path';
    import { Bundler } from 'scss-bundle';
    import * as fs from 'fs';
    
    (async () => {
      // Absolute project directory path.
      // Assuming all of your scss files are in `./projects/my-library/src/styles`
      const projectDirectory = path.resolve(__dirname, './projects/my-library/src/styles');
      const bundler = new Bundler(undefined, projectDirectory);
      // Relative file path to project directory path.
      // The name of your file here would be `app.scss`
      // Kept this here if anyone runs into this answer and wants to do this with the new angular 6 library.
      const { found, bundledContent } = await bundler.Bundle('./_all-theme.scss');
    
      if (found && bundledContent) {
        // where you want to save the file, and what you would like it to be called. 
        const location = path.resolve(__dirname, '_theming.scss');
        fs.writeFileSync(location, bundledContent);
      }
    })();

    【讨论】:

      【解决方案3】:

      scss-bundle 解决了这个问题 https://github.com/reactway/scss-bundle

      警告:不支持基于模块的较新导入。 Issue #90

      【讨论】:

        猜你喜欢
        • 2014-01-20
        • 2016-09-05
        • 2016-02-15
        • 2011-11-10
        • 2013-11-10
        • 2018-08-29
        • 2020-03-12
        • 2017-04-15
        相关资源
        最近更新 更多