1

使用Brunch作为前端原型的构建工具,我在设置UnCSS -plugin 时遇到了困难。我安装了Bootstrap 4 -skeleton 以进行快速设置,除了 UnCSS 之外,一切运行顺利。

我遇到的错误brunch build --productionerror: UnCSS: no stylesheets found. 我这样配置插件:

  plugins:
    sass:
      options:
        includePaths: [
          'bower_components/bootstrap/scss'
        ]
    postcss:
      processors: [
        require('autoprefixer')
      ]
    babel:
      ignore: [
        /^(bower_components|vendor)/
      ]
    uncss:
        options:
            csspath: 'css/app.css'
            htmlroot: 'public'
        files: ['index.html']

该项目的源文件位于appindex.htmlin app/assetsmain.scss(导入 Bootstrap)和styles.cssin app/stylesheets,和app.jsin app/javascripts

Brunch 将其构建到一个名为 的文件夹public中,其中包含样式public/css/app.css和内容public/index.html。问题是,UnCSS 的配置有什么不正确的地方?我对它的理解是它适用于构建的 CSS 输出,在这种情况下,路径似乎是正确的。

从 2014 年开始有一个关于 SO 的问题,问的问题几乎相同,但从未得到回答。

4

1 回答 1

1

我没有考虑查看 GitHub 问题,其中一个专门解决了这个问题。本质上,正如@1951FDG所建议的那样:

  plugins:
    uncss:
      options:
        ignore: [/\.\bactive\b/]
        ignoreSheets: [/fonts.googleapis/]
      files: ['public/index.html']

忽略:示例正则表达式忽略“.active”类

ignoreSheets:忽略谷歌字体的示例正则表达式

更重要的是,此 UnCSS 调用读取链接的样式表index.html以找到正确的 CSS 文件,然后对其进行处理。

于 2016-02-13T13:37:27.163 回答