@best-shot/preset-mini 0.11.16 → 0.11.17
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 +15 -18
- package/loader.mjs +92 -0
- package/package.json +6 -4
- package/transform.mjs +18 -7
package/index.mjs
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { configKeys } from '@into-mini/auto-entries-plugin/dist/helper/utils.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { applyCopy } from './transform.mjs';
|
|
3
|
+
import { applyLoaders } from './loader.mjs';
|
|
3
4
|
|
|
4
|
-
export function apply({
|
|
5
|
+
export function apply({
|
|
6
|
+
config: { copy, mini: { type, tagMatcher, preserveTap } = {} },
|
|
7
|
+
}) {
|
|
5
8
|
return async (chain) => {
|
|
6
9
|
if (chain.plugins.has('copy')) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chain
|
|
10
|
-
.plugin('copy')
|
|
11
|
-
.tap(([options]) => [
|
|
12
|
-
Array.isArray(copy)
|
|
13
|
-
? options.map((item) => ({ transform, ...item }))
|
|
14
|
-
: typeof copy === 'object'
|
|
15
|
-
? { transform, ...options }
|
|
16
|
-
: options,
|
|
17
|
-
]);
|
|
10
|
+
applyCopy(chain, { copy });
|
|
18
11
|
}
|
|
19
12
|
|
|
20
13
|
chain.output
|
|
@@ -87,9 +80,7 @@ export function apply({ config: { copy, mini: { type } = {} } }) {
|
|
|
87
80
|
|
|
88
81
|
chain.experiments.layers(true);
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// rule.test(rule.get('test').add('vue'));
|
|
83
|
+
applyLoaders(chain, { tagMatcher, preserveTap });
|
|
93
84
|
|
|
94
85
|
const { SfcSplitPlugin } = await import('@into-mini/sfc-split-plugin');
|
|
95
86
|
|
|
@@ -100,8 +91,6 @@ export function apply({ config: { copy, mini: { type } = {} } }) {
|
|
|
100
91
|
|
|
101
92
|
chain.plugin('auto-entries').use(AutoEntriesPlugin, [{ type }]);
|
|
102
93
|
|
|
103
|
-
const presets = ['vendor', 'common', 'shim', 'vue-mini', 'vue', 'react'];
|
|
104
|
-
|
|
105
94
|
const configs = Object.values(configKeys);
|
|
106
95
|
|
|
107
96
|
chain.module.rule('yaml').issuerLayer({ not: configs });
|
|
@@ -110,6 +99,8 @@ export function apply({ config: { copy, mini: { type } = {} } }) {
|
|
|
110
99
|
chain.optimization.avoidEntryIife(true);
|
|
111
100
|
|
|
112
101
|
if (chain.optimization.splitChunks.get('cacheGroups')) {
|
|
102
|
+
const presets = ['vendor', 'common', 'shim', 'vue-mini', 'vue', 'react'];
|
|
103
|
+
|
|
113
104
|
chain.optimization.splitChunks.cacheGroups(
|
|
114
105
|
Object.fromEntries(
|
|
115
106
|
Object.entries(chain.optimization.splitChunks.get('cacheGroups')).map(
|
|
@@ -139,6 +130,12 @@ export const schema = {
|
|
|
139
130
|
type: {
|
|
140
131
|
enum: ['miniprogram', 'plugin'],
|
|
141
132
|
},
|
|
133
|
+
tagMatcher: {
|
|
134
|
+
instanceof: 'Function',
|
|
135
|
+
},
|
|
136
|
+
preserveTap: {
|
|
137
|
+
instanceof: 'Function',
|
|
138
|
+
},
|
|
142
139
|
},
|
|
143
140
|
},
|
|
144
141
|
target: {
|
package/loader.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import extToRegexp from 'ext-to-regexp';
|
|
2
|
+
|
|
3
|
+
export function applyLoaders(chain) {
|
|
4
|
+
const babelRule = chain.module.rule('babel');
|
|
5
|
+
|
|
6
|
+
const vueRegexp = extToRegexp({ extname: ['vue'] });
|
|
7
|
+
|
|
8
|
+
const vueRule = chain.module.rule('vue-file').test(vueRegexp);
|
|
9
|
+
|
|
10
|
+
vueRule
|
|
11
|
+
.rule('extract-vue-javascript')
|
|
12
|
+
.test(vueRegexp)
|
|
13
|
+
.issuer(vueRegexp)
|
|
14
|
+
.resourceQuery(/type=script/)
|
|
15
|
+
.type('javascript/esm')
|
|
16
|
+
.use('babel-loader')
|
|
17
|
+
.merge(babelRule.use('babel-loader').entries())
|
|
18
|
+
.end()
|
|
19
|
+
.use('sfc-split-loader')
|
|
20
|
+
.loader('@into-mini/sfc-split-loader/dist/index.mjs');
|
|
21
|
+
|
|
22
|
+
vueRule
|
|
23
|
+
.rule('extract-vue-template')
|
|
24
|
+
.test(vueRegexp)
|
|
25
|
+
.issuer(vueRegexp)
|
|
26
|
+
.resourceQuery(/type=template/)
|
|
27
|
+
.type('asset/resource')
|
|
28
|
+
.generator.filename('[entry].wxml')
|
|
29
|
+
.end()
|
|
30
|
+
.use('wxml-loader')
|
|
31
|
+
.loader('@into-mini/wxml-loader')
|
|
32
|
+
.end()
|
|
33
|
+
.use('sfc-split-loader')
|
|
34
|
+
.loader('@into-mini/sfc-split-loader/dist/index.mjs');
|
|
35
|
+
|
|
36
|
+
vueRule
|
|
37
|
+
.rule('extract-vue-config')
|
|
38
|
+
.test(vueRegexp)
|
|
39
|
+
.issuer(vueRegexp)
|
|
40
|
+
.resourceQuery(/type=config&lang=json/)
|
|
41
|
+
.type('asset/resource')
|
|
42
|
+
.generator.filename('[entry].json')
|
|
43
|
+
.end()
|
|
44
|
+
.use('entry-loader')
|
|
45
|
+
.loader('@into-mini/sfc-split-plugin/dist/loader/entry-loader.mjs')
|
|
46
|
+
.end()
|
|
47
|
+
.use('sfc-split-loader')
|
|
48
|
+
.loader('@into-mini/sfc-split-loader/dist/index.mjs');
|
|
49
|
+
|
|
50
|
+
const xRule = vueRule
|
|
51
|
+
.rule('extract-vue-style')
|
|
52
|
+
.test(vueRegexp)
|
|
53
|
+
.issuer(vueRegexp)
|
|
54
|
+
.resourceQuery(/type=style/);
|
|
55
|
+
|
|
56
|
+
const styleRule = chain.module.rule('style');
|
|
57
|
+
|
|
58
|
+
for (const name of ['all', 'postcss', 'sass', 'less']) {
|
|
59
|
+
xRule.rule(name).merge(styleRule.rule(name).toConfig());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
xRule
|
|
63
|
+
.rule('sass')
|
|
64
|
+
.delete('test')
|
|
65
|
+
.resourceQuery(/type=style&lang=scss/);
|
|
66
|
+
|
|
67
|
+
xRule
|
|
68
|
+
.rule('less')
|
|
69
|
+
.delete('test')
|
|
70
|
+
.resourceQuery(/type=style&lang=less/);
|
|
71
|
+
|
|
72
|
+
xRule
|
|
73
|
+
.rule('extract')
|
|
74
|
+
.use('sfc-split-loader')
|
|
75
|
+
.loader('@into-mini/sfc-split-loader/dist/index.mjs');
|
|
76
|
+
|
|
77
|
+
vueRule
|
|
78
|
+
.rule('split-vue')
|
|
79
|
+
.issuer({ not: vueRegexp })
|
|
80
|
+
.resourceQuery({ not: /type=/ })
|
|
81
|
+
.type('javascript/esm')
|
|
82
|
+
.use('sfc-split-loader')
|
|
83
|
+
.loader('@into-mini/sfc-split-loader/dist/index.mjs');
|
|
84
|
+
|
|
85
|
+
// vueRule
|
|
86
|
+
// .rule('pre-vue').issuer({ not: vueRegexp })
|
|
87
|
+
// .resourceQuery({ not: /type=/ })
|
|
88
|
+
// .use('sfc-split-loader')
|
|
89
|
+
// .use('sfc-split-pre')
|
|
90
|
+
// .loader('@into-mini/sfc-split-loader/dist/next.mjs')
|
|
91
|
+
// .options(options)
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@best-shot/preset-mini",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.17",
|
|
4
4
|
"description": "A `best-shot` preset for mini program project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,14 +29,16 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@into-mini/auto-entries-plugin": "^0.2.0",
|
|
31
31
|
"@into-mini/sfc-split-loader": "^0.2.6",
|
|
32
|
-
"@into-mini/sfc-split-plugin": "^0.
|
|
32
|
+
"@into-mini/sfc-split-plugin": "^0.6.0",
|
|
33
|
+
"@into-mini/wxml-loader": "^0.0.0",
|
|
34
|
+
"ext-to-regexp": "^0.1.0",
|
|
33
35
|
"yaml": "^2.8.2"
|
|
34
36
|
},
|
|
35
37
|
"peerDependencies": {
|
|
36
38
|
"@babel/core": "^7.28.5",
|
|
37
|
-
"@best-shot/core": "^0.13.
|
|
39
|
+
"@best-shot/core": "^0.13.10",
|
|
38
40
|
"@best-shot/preset-babel": "^0.18.6",
|
|
39
|
-
"@best-shot/preset-style": "^0.16.
|
|
41
|
+
"@best-shot/preset-style": "^0.16.3"
|
|
40
42
|
},
|
|
41
43
|
"engines": {
|
|
42
44
|
"node": ">=22.11.0"
|
package/transform.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import babel from '@babel/core';
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.get('options');
|
|
9
|
-
const minimize = chain.optimization.get('minimize');
|
|
3
|
+
export function applyCopy(chain, { copy }) {
|
|
4
|
+
const { targets } = chain.module
|
|
5
|
+
.rule('babel')
|
|
6
|
+
.use('babel-loader')
|
|
7
|
+
.get('options');
|
|
10
8
|
|
|
9
|
+
const minimize = chain.optimization.get('minimize');
|
|
10
|
+
|
|
11
|
+
const transform = (input, absoluteFrom) => {
|
|
11
12
|
if (!absoluteFrom.endsWith('.js') || absoluteFrom.endsWith('.mjs')) {
|
|
12
13
|
return input;
|
|
13
14
|
}
|
|
@@ -33,4 +34,14 @@ export function transformJS(chain) {
|
|
|
33
34
|
';',
|
|
34
35
|
);
|
|
35
36
|
};
|
|
37
|
+
|
|
38
|
+
chain
|
|
39
|
+
.plugin('copy')
|
|
40
|
+
.tap(([options]) => [
|
|
41
|
+
Array.isArray(copy)
|
|
42
|
+
? options.map((item) => ({ transform, ...item }))
|
|
43
|
+
: typeof copy === 'object'
|
|
44
|
+
? { transform, ...options }
|
|
45
|
+
: options,
|
|
46
|
+
]);
|
|
36
47
|
}
|