Skip to content
This repository was archived by the owner on Feb 8, 2022. It is now read-only.

Commit a3c959c

Browse files
author
Brandon Pittman
committed
Fix PurgeCSS 2.0 deep scope issue
1 parent d97e144 commit a3c959c

File tree

1 file changed

+72
-70
lines changed

1 file changed

+72
-70
lines changed

gridsome.server.js

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,93 @@
11
function TailwindPlugin(api, options) {
2-
const {
3-
tailwindConfig,
4-
purgeConfig,
5-
presetEnvConfig,
6-
shouldImport,
7-
shouldPurge,
8-
shouldTimeTravel
9-
} = options;
2+
const {
3+
tailwindConfig,
4+
purgeConfig,
5+
presetEnvConfig,
6+
shouldImport,
7+
shouldPurge,
8+
shouldTimeTravel
9+
} = options;
1010

11-
const postcssImport = require('postcss-import')();
11+
const postcssImport = require('postcss-import')();
1212

13-
const tailwind = tailwindConfig ?
14-
require('tailwindcss')(tailwindConfig) :
15-
require('tailwindcss');
13+
const tailwind = tailwindConfig ?
14+
require('tailwindcss')(tailwindConfig) :
15+
require('tailwindcss');
1616

17-
const postcssPresetEnv = require('postcss-preset-env')(presetEnvConfig);
18-
const purgecss = require('@fullhuman/postcss-purgecss')(purgeConfig);
17+
const postcssPresetEnv = require('postcss-preset-env')(presetEnvConfig);
18+
const purgecss = require('@fullhuman/postcss-purgecss')(purgeConfig);
1919

20-
api.chainWebpack(config => {
21-
// I'm giving into peer pressure.
22-
['css', 'scss', 'sass', 'less', 'stylus', 'postcss'].forEach(lang => {
23-
config.module
24-
.rule(lang)
25-
.oneOf('normal')
26-
.use('postcss-loader')
27-
.tap(options => {
28-
options.plugins.unshift(
29-
...[
30-
shouldImport && postcssImport,
31-
tailwind,
32-
shouldTimeTravel && postcssPresetEnv
33-
]
34-
);
20+
api.chainWebpack(config => {
21+
// I'm giving into peer pressure.
22+
['css', 'scss', 'sass', 'less', 'stylus', 'postcss'].forEach(lang => {
23+
config.module
24+
.rule(lang)
25+
.oneOf('normal')
26+
.use('postcss-loader')
27+
.tap(options => {
28+
options.plugins.unshift(
29+
...[
30+
shouldImport && postcssImport,
31+
tailwind,
32+
shouldTimeTravel && postcssPresetEnv
33+
]
34+
);
3535

36-
// eslint-disable-next-line no-unused-expressions
37-
process.env.NODE_ENV === 'production' &&
36+
// eslint-disable-next-line no-unused-expressions
37+
process.env.NODE_ENV === 'production' &&
3838
shouldPurge &&
3939
options.plugins.push(purgecss);
4040

41-
return options;
42-
});
43-
});
44-
});
41+
return options;
42+
});
43+
});
44+
});
4545
}
4646

4747
TailwindPlugin.defaultOptions = () => ({
48-
shouldPurge: true,
49-
shouldImport: true,
50-
shouldTimeTravel: true,
51-
tailwindConfig: undefined,
52-
presetEnvConfig: {
53-
stage: 0,
54-
autoprefixer: false
55-
},
56-
purgeConfig: {
57-
keyframes: true,
58-
content: [
59-
'./src/**/*.vue',
60-
'./src/**/*.js',
61-
'./src/**/*.jsx',
62-
'./src/**/*.ts',
63-
'./src/**/*.tsx',
64-
'./src/**/*.html',
65-
'./src/**/*.pug',
66-
'./src/**/*.md',
67-
'./src/**/*.svg'
68-
],
69-
whitelist: [
70-
'body',
71-
'html',
72-
'img',
73-
'a',
74-
'g-image',
75-
'g-image--lazy',
76-
'g-image--loaded',
77-
'active',
78-
'active--exact'
79-
],
48+
shouldPurge: true,
49+
shouldImport: true,
50+
shouldTimeTravel: true,
51+
tailwindConfig: undefined,
52+
presetEnvConfig: {
53+
stage: 0,
54+
autoprefixer: false
55+
},
56+
purgeConfig: {
57+
keyframes: true,
58+
content: [
59+
'./src/**/*.vue',
60+
'./src/**/*.js',
61+
'./src/**/*.jsx',
62+
'./src/**/*.ts',
63+
'./src/**/*.tsx',
64+
'./src/**/*.html',
65+
'./src/**/*.pug',
66+
'./src/**/*.md',
67+
'./src/**/*.svg'
68+
],
69+
whitelist: [
70+
'body',
71+
'html',
72+
'img',
73+
'a',
74+
'g-image',
75+
'g-image--lazy',
76+
'g-image--loaded',
77+
'active',
78+
'active--exact'
79+
],
8080
whitelistPatterns: [
8181
/shiki/,
8282
/prism/,
8383
/markdown/,
8484
/.*-(enter|enter-active|enter-to|leave|leave-active|leave-to)/,
85-
/data-v-.*/
85+
/data-v-.*/,
86+
/>>>/,
87+
/::v-deep/
8688
],
87-
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
88-
}
89+
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
90+
}
8991
});
9092

9193
module.exports = TailwindPlugin;

0 commit comments

Comments
 (0)