Skip to content

Commit

Permalink
merge !116
Browse files Browse the repository at this point in the history
resolves #112 unmangle pseudo-element selectors
  • Loading branch information
mojavelinux committed May 1, 2020
2 parents 3c8aacc + 7fe0510 commit 9d1b0d0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gulp.d/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), [])
Expand All @@ -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(
Expand Down Expand Up @@ -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(',')
})
}

0 comments on commit 9d1b0d0

Please sign in to comment.