@best-shot/preset-mini 0.11.13 → 0.11.14
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 +20 -1
- package/package.json +4 -3
- package/transform.mjs +34 -0
package/index.mjs
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { configKeys } from '@into-mini/auto-entries-plugin/helper/utils.mjs';
|
|
2
|
+
import { transformJS } from './transform.mjs';
|
|
2
3
|
|
|
3
|
-
export function apply({ config: { mini: { type } = {} } }) {
|
|
4
|
+
export function apply({ config: { copy, mini: { type } = {} } }) {
|
|
4
5
|
return async (chain) => {
|
|
6
|
+
if (chain.plugins.has('copy')) {
|
|
7
|
+
const { targets } = chain.module
|
|
8
|
+
.rule('babel')
|
|
9
|
+
.use('babel-loader')
|
|
10
|
+
.get('options');
|
|
11
|
+
const transform = transformJS(targets);
|
|
12
|
+
|
|
13
|
+
chain
|
|
14
|
+
.plugin('copy')
|
|
15
|
+
.tap(([options]) => [
|
|
16
|
+
Array.isArray(copy)
|
|
17
|
+
? options.map((item) => ({ transform, ...item }))
|
|
18
|
+
: typeof copy === 'object'
|
|
19
|
+
? { transform, ...options }
|
|
20
|
+
: options,
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
|
|
5
24
|
chain.output
|
|
6
25
|
.publicPath('/')
|
|
7
26
|
.iife(false)
|
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.14",
|
|
4
4
|
"description": "A `best-shot` preset for mini program project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"yaml": "^2.8.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
+
"@babel/core": "^7.28.5",
|
|
35
36
|
"@best-shot/core": "^0.13.9",
|
|
36
|
-
"@best-shot/preset-
|
|
37
|
-
"@best-shot/preset-
|
|
37
|
+
"@best-shot/preset-style": "^0.16.1",
|
|
38
|
+
"@best-shot/preset-babel": "^0.18.6"
|
|
38
39
|
},
|
|
39
40
|
"engines": {
|
|
40
41
|
"node": ">=22.11.0"
|
package/transform.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import babel from '@babel/core';
|
|
2
|
+
|
|
3
|
+
export function transformJS(targets) {
|
|
4
|
+
console.log(targets);
|
|
5
|
+
|
|
6
|
+
return (input, absoluteFrom) => {
|
|
7
|
+
const minified = process.env.NODE_ENV === 'production';
|
|
8
|
+
|
|
9
|
+
if (!absoluteFrom.endsWith('.js') || absoluteFrom.endsWith('.mjs')) {
|
|
10
|
+
return input;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const result = babel.transformSync(input, {
|
|
14
|
+
presets: [['babel-preset-evergreen', { usage: 'pure', mini: true }]],
|
|
15
|
+
plugins: [
|
|
16
|
+
['@babel/plugin-transform-modules-commonjs', { importInterop: 'none' }],
|
|
17
|
+
],
|
|
18
|
+
targets,
|
|
19
|
+
configFile: false,
|
|
20
|
+
babelrc: false,
|
|
21
|
+
filename: 'a.mjs',
|
|
22
|
+
sourceType: 'commonjs',
|
|
23
|
+
compact: !minified,
|
|
24
|
+
retainLines: !minified,
|
|
25
|
+
envName: process.env.NODE_ENV,
|
|
26
|
+
minified,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return (result?.code || input).replace(
|
|
30
|
+
';Object.defineProperty(exports,"__esModule",{value:true});',
|
|
31
|
+
';',
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
}
|