From 7fe0510a14fcee94d2f6703b5ad1456545ae5bf0 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Wed, 29 Apr 2020 05:41:29 -0600 Subject: [PATCH] unmangle pseudo-element selectors --- gulp.d/tasks/build.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gulp.d/tasks/build.js b/gulp.d/tasks/build.js index 7a29aa3..5894cc1 100644 --- a/gulp.d/tasks/build.js +++ b/gulp.d/tasks/build.js @@ -24,7 +24,7 @@ module.exports = (src, dest, preview) => () => { const sourcemaps = preview || process.env.SOURCEMAPS === 'true' const postcssPlugins = [ postcssImport, - (root, { messages, opts: { file } }) => + (css, { messages, opts: { file } }) => Promise.all( messages .reduce((accum, { file: depPath, type }) => (type === 'dependency' ? accum.concat(depPath) : accum), []) @@ -49,7 +49,9 @@ module.exports = (src, dest, preview) => () => { postcssVar({ preserve: preview }), preview ? postcssCalc : () => {}, autoprefixer, - preview ? () => {} : cssnano({ preset: 'default' }), + preview + ? () => {} + : (css, result) => cssnano({ preset: 'default' })(css, result).then(() => postcssPseudoElementFixer(css, result)), ] return merge( @@ -111,3 +113,9 @@ module.exports = (src, dest, preview) => () => { vfs.src('partials/*.hbs', opts) ).pipe(vfs.dest(dest, { sourcemaps: sourcemaps && '.' })) } + +function postcssPseudoElementFixer (css, result) { + css.walkRules(/(?:^|[^:]):(?:before|after)/, (rule) => { + rule.selector = rule.selectors.map((it) => it.replace(/(^|[^:]):(before|after)$/, '$1::$2')).join(',') + }) +}