3

基本的postcss.config.js看起来像这样

const purgecss = require('@fullhuman/postcss-purgecss')

module.exports = {
  plugins: [
    purgecss({
      content: ['./**/*.html']
    })
  ]
}

我有一种情况,我需要定义带有嵌套子目录的文件夹的路径。我发现的唯一解释是这个:

content: [
    // keep only those that you need
    '**/*.html' // will look inside any folder for an .html file
    '!(bar)/**/*.html' // will look inside any folder that is not 'bar'
    '!({bar,foo})/**/*.html' // will look inside any folder that is nor 'bar' nor 'foo'
    '!(bar-*)/**/*.html' // will look inside any folder that does not start with 'bar-'
  ],
  css: [`**/*.css`],

...但我想要一些不同的东西:如何定义文件夹及其所有子目录(及其子目录等)的路径?

有类似的东西

glob.glob('**/*.txt',recursive=True): 匹配当前目录和所有子目录中所有以 '.txt' 结尾的文件

如何recursive=True在 PostCSS/PurgeCSS 中设置选项?

4

1 回答 1

0

我的postcss.config.js样子是这样的:

const themeDir = __dirname + '/../../';

const purgecss = require('@fullhuman/postcss-purgecss')({

    // Specify the paths to all of the template files in your project
    content: [
        themeDir + 'layouts/**/*.html',
        themeDir + 'content/**/*.html',
        'layouts/**/*.html',
        'content/**/*.html',
        // Specify path to own javascript
        themeDir + 'assets/js/**/*.js',
    ],
于 2021-05-21T11:47:17.320 回答