@best-shot/preset-style 0.16.2 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +44 -10
- package/lib/apply-scss-less.mjs +4 -1
- package/lib/apply-stylesheet.mjs +7 -53
- package/package.json +8 -8
package/index.mjs
CHANGED
|
@@ -1,11 +1,54 @@
|
|
|
1
|
+
import slashToRegexp from 'slash-to-regexp';
|
|
1
2
|
import { applyScssLess } from './lib/apply-scss-less.mjs';
|
|
2
3
|
import { applyStylesheet } from './lib/apply-stylesheet.mjs';
|
|
3
4
|
|
|
4
5
|
export function apply({ config: { css: { extract } = {} } }) {
|
|
5
6
|
return async (chain) => {
|
|
6
|
-
|
|
7
|
+
const hot = chain.devServer.get('hot');
|
|
8
|
+
|
|
9
|
+
const needExtract = extract ? true : !hot;
|
|
10
|
+
|
|
11
|
+
const { default: MiniCssExtractPlugin } =
|
|
12
|
+
await import('mini-css-extract-plugin');
|
|
13
|
+
|
|
14
|
+
await applyStylesheet({ needExtract, MiniCssExtractPlugin })(chain);
|
|
7
15
|
|
|
8
16
|
applyScssLess()(chain);
|
|
17
|
+
|
|
18
|
+
if (needExtract) {
|
|
19
|
+
chain.plugin('extract-css').use(MiniCssExtractPlugin, [
|
|
20
|
+
{
|
|
21
|
+
ignoreOrder: true,
|
|
22
|
+
experimentalUseImportModule: true,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (chain.module.rules.has('babel')) {
|
|
28
|
+
chain.module
|
|
29
|
+
.rule('babel')
|
|
30
|
+
.exclude.add(slashToRegexp('/node_modules/css-loader/'));
|
|
31
|
+
|
|
32
|
+
if (needExtract) {
|
|
33
|
+
chain.module
|
|
34
|
+
.rule('babel')
|
|
35
|
+
.exclude.add(slashToRegexp('/node_modules/mini-css-extract-plugin/'));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const minimize = chain.optimization.get('minimize');
|
|
40
|
+
|
|
41
|
+
if (minimize) {
|
|
42
|
+
const { default: CssMinimizerPlugin } =
|
|
43
|
+
await import('css-minimizer-webpack-plugin');
|
|
44
|
+
chain.optimization.minimizer('css-minimizer').use(CssMinimizerPlugin, [
|
|
45
|
+
{
|
|
46
|
+
minimizerOptions: {
|
|
47
|
+
preset: ['default', { discardComments: { removeAll: true } }],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
9
52
|
};
|
|
10
53
|
}
|
|
11
54
|
|
|
@@ -22,13 +65,4 @@ export const schema = {
|
|
|
22
65
|
},
|
|
23
66
|
},
|
|
24
67
|
},
|
|
25
|
-
output: {
|
|
26
|
-
type: 'object',
|
|
27
|
-
default: {},
|
|
28
|
-
properties: {
|
|
29
|
-
cssFilename: {
|
|
30
|
-
default: '.css',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
68
|
};
|
package/lib/apply-scss-less.mjs
CHANGED
|
@@ -8,10 +8,12 @@ function addExtname(rule) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function applyScssLess() {
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
12
|
+
return (chain) => {
|
|
12
13
|
chain.module.rule('style').batch(addExtname);
|
|
13
14
|
|
|
14
15
|
chain.module
|
|
16
|
+
.rule('style')
|
|
15
17
|
.rule('sass')
|
|
16
18
|
.test(extToRegexp({ extname: ['scss', 'sass'] }))
|
|
17
19
|
.use('resolve-url-loader')
|
|
@@ -28,6 +30,7 @@ export function applyScssLess() {
|
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
chain.module
|
|
33
|
+
.rule('style')
|
|
31
34
|
.rule('less')
|
|
32
35
|
.after('sass')
|
|
33
36
|
.test(extToRegexp({ extname: ['less'] }))
|
package/lib/apply-stylesheet.mjs
CHANGED
|
@@ -2,29 +2,13 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
|
|
3
3
|
import extToRegexp from 'ext-to-regexp';
|
|
4
4
|
import { haveDevDependencies, haveLocalDependencies } from 'settingz';
|
|
5
|
-
import slashToRegexp from 'slash-to-regexp';
|
|
6
5
|
|
|
7
6
|
const auto = (resourcePath, resourceQuery) =>
|
|
8
7
|
/\.module\.\w+$/i.test(resourcePath) ||
|
|
9
8
|
new URLSearchParams(resourceQuery).get('module');
|
|
10
9
|
|
|
11
|
-
export function applyStylesheet({
|
|
10
|
+
export function applyStylesheet({ needExtract, MiniCssExtractPlugin }) {
|
|
12
11
|
return async (chain) => {
|
|
13
|
-
const minimize = chain.optimization.get('minimize');
|
|
14
|
-
|
|
15
|
-
if (minimize) {
|
|
16
|
-
const { default: CssMinimizerPlugin } = await import(
|
|
17
|
-
'css-minimizer-webpack-plugin'
|
|
18
|
-
);
|
|
19
|
-
chain.optimization.minimizer('css-minimizer').use(CssMinimizerPlugin, [
|
|
20
|
-
{
|
|
21
|
-
minimizerOptions: {
|
|
22
|
-
preset: ['default', { discardComments: { removeAll: true } }],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
]);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
12
|
const rule = chain.module
|
|
29
13
|
.rule('style')
|
|
30
14
|
.after('esm')
|
|
@@ -41,37 +25,7 @@ export function applyStylesheet({ extract }) {
|
|
|
41
25
|
.dependency('url')
|
|
42
26
|
.generator.filename(assetModuleFilename.replace('[ext]', cssFilename));
|
|
43
27
|
|
|
44
|
-
const { default: MiniCssExtractPlugin } = await import(
|
|
45
|
-
'mini-css-extract-plugin'
|
|
46
|
-
);
|
|
47
|
-
|
|
48
28
|
const mode = chain.get('mode');
|
|
49
|
-
const hot = chain.devServer.get('hot');
|
|
50
|
-
|
|
51
|
-
const needExtract = extract ? true : !hot;
|
|
52
|
-
|
|
53
|
-
if (needExtract) {
|
|
54
|
-
chain.plugin('extract-css').use(MiniCssExtractPlugin, [
|
|
55
|
-
{
|
|
56
|
-
filename: `[name]${cssFilename}`,
|
|
57
|
-
// chunkFilename: '[id].css',
|
|
58
|
-
ignoreOrder: true,
|
|
59
|
-
experimentalUseImportModule: true,
|
|
60
|
-
},
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (chain.module.rules.has('babel')) {
|
|
65
|
-
chain.module
|
|
66
|
-
.rule('babel')
|
|
67
|
-
.exclude.add(slashToRegexp('/node_modules/css-loader/'));
|
|
68
|
-
|
|
69
|
-
if (needExtract) {
|
|
70
|
-
chain.module
|
|
71
|
-
.rule('babel')
|
|
72
|
-
.exclude.add(slashToRegexp('/node_modules/mini-css-extract-plugin/'));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
29
|
|
|
76
30
|
const parent = rule.rule('all').oneOf('not-url').dependency({ not: 'url' });
|
|
77
31
|
|
|
@@ -107,12 +61,12 @@ export function applyStylesheet({ extract }) {
|
|
|
107
61
|
.options({
|
|
108
62
|
postcssOptions: {
|
|
109
63
|
plugins: haveLocalDependencies('tailwindcss')
|
|
110
|
-
?
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
]
|
|
64
|
+
? haveDevDependencies('@tailwindcss/postcss')
|
|
65
|
+
? [
|
|
66
|
+
'@tailwindcss/postcss',
|
|
67
|
+
'postcss-preset-evergreen/lib/tailwind.cjs',
|
|
68
|
+
]
|
|
69
|
+
: ['tailwindcss', 'postcss-preset-evergreen']
|
|
116
70
|
: ['postcss-preset-evergreen'],
|
|
117
71
|
},
|
|
118
72
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@best-shot/preset-style",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"description": "A `best-shot` preset for stylesheet",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -34,28 +34,28 @@
|
|
|
34
34
|
"main": "index.mjs",
|
|
35
35
|
"type": "module",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"css-loader": "^7.1.
|
|
37
|
+
"css-loader": "^7.1.3",
|
|
38
38
|
"css-minimizer-webpack-plugin": "^7.0.4",
|
|
39
39
|
"cssnano": "^7.1.2",
|
|
40
40
|
"ext-to-regexp": "^0.1.0",
|
|
41
41
|
"less": "^4.5.1",
|
|
42
|
-
"less-loader": "^12.3.
|
|
43
|
-
"mini-css-extract-plugin": "^2.
|
|
42
|
+
"less-loader": "^12.3.1",
|
|
43
|
+
"mini-css-extract-plugin": "^2.10.0",
|
|
44
44
|
"postcss": "^8.5.6",
|
|
45
45
|
"postcss-loader": "^8.2.0",
|
|
46
46
|
"postcss-preset-evergreen": "^0.8.2",
|
|
47
47
|
"resolve-url-loader": "^5.0.0",
|
|
48
|
-
"sass-embedded": "^1.97.
|
|
49
|
-
"sass-loader": "^16.0.
|
|
48
|
+
"sass-embedded": "^1.97.3",
|
|
49
|
+
"sass-loader": "^16.0.7",
|
|
50
50
|
"settingz": "^0.2.0",
|
|
51
51
|
"slash-to-regexp": "^0.1.0",
|
|
52
52
|
"style-loader": "^4.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@best-shot/core": "^0.13.
|
|
55
|
+
"@best-shot/core": "^0.13.11"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
|
-
"node": ">=22.
|
|
58
|
+
"node": ">=22.18.0"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public",
|