PostCSS:运行任务时,PurgeCSS不起作用

问题描述

我目前正在尝试从项目的样式表中删除未使用的CSS。我有一个gulp任务sass,所有编译都已完成。我正在使用postcsspurgecss插件。但是,当我运行sass任务purgecss时似乎不起作用。

gulp.task('sass',() => gulp.src(`${SRC}/scss/style-*.scss`)
  .pipe(sourcemaps.init())
  .pipe(gulpSass({
    includePaths: ['node_modules',`${PATTERNS_ACCESS}/src/`]
    .concat(require('bourbon').includePaths)
  })
  .on('error',gulpSass.logError))
  .pipe(postcss([
    purgecss({
      content: ['./views/**/*.twig']
    }),autoprefixer(),mqpacker({sort: true}),cssnano()
  ]))
  .pipe(hashFilename({format: HASH_FORMAT}))
  .pipe(sourcemaps.write('./'))
  .pipe(gulp.dest('./assets/styles'))
);

上面,如果您注意到purgecss,我将其传递至应该从中删除CSS的模板的路径。使用PostCSS API following the documentation添加模板的目录:

const purgecss = require('@fullhuman/postcss-purgecss')
postcss([
  purgecss({
    content: ['./src/**/*.html']
  })
])

除了purgecss之外,我还应该在content添加配置吗? 问题可能是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)