vite-plugin-taro 0.4.1 → 0.5.0
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/dist/node/plugins/wx/dev/create-wx-dev-mode.d.ts +6 -0
- package/dist/node/plugins/wx/dev/create-wx-dev-mode.js +9 -0
- package/dist/node/plugins/wx/dev/dev-host.js +17 -7
- package/dist/node/plugins/wx/dev/empty-output-directory.d.ts +2 -0
- package/dist/node/plugins/wx/dev/empty-output-directory.js +10 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +2 -2
- package/dist/node/utils/transform.d.ts +1 -1
- package/dist/node/utils/transform.js +1 -1
- package/package.json +14 -12
- package/src/node/babel-plugins.d.ts +20 -0
- package/src/node/plugins/h5/plugins.ts +2 -2
- package/src/node/plugins/wx/dev/create-wx-dev-mode.ts +14 -0
- package/src/node/plugins/wx/dev/dev-host.ts +21 -8
- package/src/node/plugins/wx/dev/empty-output-directory.ts +14 -0
- package/src/node/plugins/wx/dev/react-refresh.ts +5 -5
- package/src/node/plugins/wx/render/capsule-wrapper.ts +2 -2
- package/src/node/plugins/wx/render/native.ts +2 -2
- package/src/node/utils/transform.ts +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InputOptions } from 'rolldown';
|
|
2
|
+
type DevMode = NonNullable<NonNullable<InputOptions['experimental']>['devMode']>;
|
|
3
|
+
type DevModeOptions = Exclude<DevMode, boolean>;
|
|
4
|
+
/** Installs the custom WX runtime while restoring Rolldown's common runtime base. */
|
|
5
|
+
export declare function createWxDevMode(devMode: DevMode | undefined, implement: string): DevModeOptions;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Installs the custom WX runtime while restoring Rolldown's common runtime base. */
|
|
2
|
+
export function createWxDevMode(devMode, implement) {
|
|
3
|
+
return {
|
|
4
|
+
...(typeof devMode === 'object' ? devMode : {}),
|
|
5
|
+
implement,
|
|
6
|
+
lazy: false,
|
|
7
|
+
skipCommonRuntimeInjection: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -5,6 +5,8 @@ import { dev, viteReporterPlugin } from 'rolldown/experimental';
|
|
|
5
5
|
import { once } from '../../../utils/once.js';
|
|
6
6
|
import { resolvePackageFile } from '../../../utils/packages.js';
|
|
7
7
|
import { appShellFileName } from '../module.js';
|
|
8
|
+
import { createWxDevMode } from './create-wx-dev-mode.js';
|
|
9
|
+
import { emptyOutputDirectory } from './empty-output-directory.js';
|
|
8
10
|
import { hmrControlPath, hmrInfoFileName, hmrPatchesFileName, renderHmrInfo, renderInitialHmrPatches, writeHmrFile } from './hmr-files.js';
|
|
9
11
|
import { PatchPublisher } from './patch-publisher.js';
|
|
10
12
|
/**
|
|
@@ -184,18 +186,26 @@ export async function createWxDevHost({ server, options }) {
|
|
|
184
186
|
sourcemap: false
|
|
185
187
|
});
|
|
186
188
|
rolldownOptions.experimental ??= {};
|
|
187
|
-
rolldownOptions.experimental.devMode =
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
rolldownOptions.experimental.devMode = createWxDevMode(rolldownOptions.experimental.devMode, await bundleRuntimeSource());
|
|
190
|
+
const emptyOutputDirectoryPlugin = {
|
|
191
|
+
name: 'vpt:wx-empty-output-directory',
|
|
192
|
+
renderStart: {
|
|
193
|
+
order: 'pre',
|
|
194
|
+
// DevEngine bypasses Vite's build-only output preparation. Clear stale files before every complete
|
|
195
|
+
// physical render while retaining the directory watched by WeChat DevTools.
|
|
196
|
+
handler: () => emptyOutputDirectory(server.config.build.outDir)
|
|
197
|
+
}
|
|
193
198
|
};
|
|
194
199
|
const reportInitialBuildPlugin = {
|
|
195
200
|
name: 'vpt:wx-report-initial-build',
|
|
196
201
|
buildEnd: settleInitialBuild
|
|
197
202
|
};
|
|
198
|
-
rolldownOptions.plugins = [
|
|
203
|
+
rolldownOptions.plugins = [
|
|
204
|
+
emptyOutputDirectoryPlugin,
|
|
205
|
+
rolldownOptions.plugins,
|
|
206
|
+
reportInitialBuildPlugin,
|
|
207
|
+
createViteReporter(server)
|
|
208
|
+
];
|
|
199
209
|
disableViteOxcSourcemap(rolldownOptions.plugins);
|
|
200
210
|
return rolldownOptions;
|
|
201
211
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Empties an output directory without replacing the directory itself or deleting Git metadata. */
|
|
4
|
+
export async function emptyOutputDirectory(directory) {
|
|
5
|
+
await fs.mkdir(directory, { recursive: true });
|
|
6
|
+
const entries = await fs.readdir(directory);
|
|
7
|
+
await Promise.all(entries
|
|
8
|
+
.filter((entry) => entry !== '.git')
|
|
9
|
+
.map((entry) => fs.rm(path.join(directory, entry), { force: true, recursive: true })));
|
|
10
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PluginObj } from '@babel/core';
|
|
2
2
|
/** Wraps System.register as an inert CommonJS capsule tuple with canonical final dependency IDs. */
|
|
3
|
-
export declare function wrapCapsulePlugin(fileName: string):
|
|
3
|
+
export declare function wrapCapsulePlugin(fileName: string): PluginObj;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { transformSync } from '@babel/core';
|
|
2
|
-
import generate from '@babel/generator';
|
|
2
|
+
import { generate } from '@babel/generator';
|
|
3
3
|
import { transformWithOxc } from 'vite';
|
|
4
4
|
import { esTarget } from './constant.js';
|
|
5
5
|
/** Replaces each placeholder with a Babel AST expression while transforming the module through Oxc. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "sep2",
|
|
5
5
|
"description": "Vite 8 plugin for building one React/Taro codebase for WeChat Mini Program and H5 targets.",
|
|
6
6
|
"type": "module",
|
|
@@ -51,14 +51,13 @@
|
|
|
51
51
|
"node": "^22.18.0 || >=24.11.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@babel/core": "^
|
|
55
|
-
"@babel/generator": "^
|
|
56
|
-
"@babel/plugin-transform-dynamic-import": "^
|
|
57
|
-
"@babel/plugin-transform-modules-commonjs": "^
|
|
58
|
-
"@babel/plugin-transform-modules-systemjs": "^
|
|
54
|
+
"@babel/core": "^7.29.7",
|
|
55
|
+
"@babel/generator": "^7.29.8",
|
|
56
|
+
"@babel/plugin-transform-dynamic-import": "^7.29.7",
|
|
57
|
+
"@babel/plugin-transform-modules-commonjs": "^7.29.7",
|
|
58
|
+
"@babel/plugin-transform-modules-systemjs": "^7.29.8",
|
|
59
59
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
60
60
|
"@tailwindcss-mangle/engine": "0.2.0",
|
|
61
|
-
"@weapp-tailwindcss/postcss": "3.2.8",
|
|
62
61
|
"@tarojs/components": "^4.2.0",
|
|
63
62
|
"@tarojs/helper": "^4.2.0",
|
|
64
63
|
"@tarojs/plugin-platform-h5": "^4.2.0",
|
|
@@ -67,28 +66,31 @@
|
|
|
67
66
|
"@tarojs/runtime": "^4.2.0",
|
|
68
67
|
"@tarojs/taro": "^4.2.0",
|
|
69
68
|
"@vitejs/plugin-react": "^6.0.5",
|
|
69
|
+
"@weapp-tailwindcss/postcss": "3.2.8",
|
|
70
70
|
"babel-plugin-transform-taroapi": "^4.2.0",
|
|
71
71
|
"picocolors": "^1.1.1",
|
|
72
72
|
"react-reconciler": "0.33.0",
|
|
73
73
|
"react-refresh": "^0.18.0",
|
|
74
|
-
"rolldown": "
|
|
74
|
+
"rolldown": "1.2.3",
|
|
75
75
|
"tailwindcss": "^4.3.3",
|
|
76
76
|
"weapp-tailwindcss": "^5.2.11",
|
|
77
|
-
"@tarojs/react": "npm:vite-plugin-taro-react@0.
|
|
78
|
-
"@tarojs/
|
|
77
|
+
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.0",
|
|
78
|
+
"@tarojs/react": "npm:vite-plugin-taro-react@0.5.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": "^19.0.0",
|
|
82
82
|
"react-dom": "^19.0.0",
|
|
83
|
-
"vite": "
|
|
83
|
+
"vite": "8.2.1"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
+
"@types/babel__core": "^7.20.5",
|
|
87
|
+
"@types/babel__generator": "^7.27.0",
|
|
86
88
|
"@types/node": "^26.1.1",
|
|
87
89
|
"@types/react": "^19.2.17",
|
|
88
90
|
"@types/react-dom": "^19.2.3",
|
|
89
91
|
"@types/react-refresh": "^0.14.7",
|
|
90
92
|
"typescript": "^7.0.2",
|
|
91
|
-
"vite": "
|
|
93
|
+
"vite": "8.2.1"
|
|
92
94
|
},
|
|
93
95
|
"scripts": {
|
|
94
96
|
"build": "node ../../scripts/sync-plugin-readme.ts && node ../../scripts/clean-directory.ts dist && tsc --project tsconfig.build.json",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare module '@babel/plugin-transform-dynamic-import' {
|
|
2
|
+
import type { PluginTarget } from '@babel/core'
|
|
3
|
+
|
|
4
|
+
const transformDynamicImport: PluginTarget
|
|
5
|
+
export default transformDynamicImport
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module '@babel/plugin-transform-modules-commonjs' {
|
|
9
|
+
import type { PluginTarget } from '@babel/core'
|
|
10
|
+
|
|
11
|
+
const transformModulesCommonjs: PluginTarget
|
|
12
|
+
export default transformModulesCommonjs
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@babel/plugin-transform-modules-systemjs' {
|
|
16
|
+
import type { PluginTarget } from '@babel/core'
|
|
17
|
+
|
|
18
|
+
const transformModulesSystemjs: PluginTarget
|
|
19
|
+
export default transformModulesSystemjs
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { types as BabelTypes } from '@babel/core'
|
|
2
|
-
import { type NodePath, type
|
|
2
|
+
import { type NodePath, type PluginObj, types } from '@babel/core'
|
|
3
3
|
import babel from '@rolldown/plugin-babel'
|
|
4
4
|
import type { HtmlTagDescriptor, Plugin, PluginOption } from 'vite'
|
|
5
5
|
import type { VitePluginTaroOptions } from '../../../options.ts'
|
|
@@ -127,7 +127,7 @@ function createH5SupportPlugins(): PluginOption[] {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/** Keeps Stencil-injected Taro component styles before application stylesheets. */
|
|
130
|
-
function rewriteStencilStyleInsertion():
|
|
130
|
+
function rewriteStencilStyleInsertion(): PluginObj {
|
|
131
131
|
return {
|
|
132
132
|
name: 'vpt:rewrite-stencil-style-insertion',
|
|
133
133
|
visitor: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InputOptions } from 'rolldown'
|
|
2
|
+
|
|
3
|
+
type DevMode = NonNullable<NonNullable<InputOptions['experimental']>['devMode']>
|
|
4
|
+
type DevModeOptions = Exclude<DevMode, boolean>
|
|
5
|
+
|
|
6
|
+
/** Installs the custom WX runtime while restoring Rolldown's common runtime base. */
|
|
7
|
+
export function createWxDevMode(devMode: DevMode | undefined, implement: string): DevModeOptions {
|
|
8
|
+
return {
|
|
9
|
+
...(typeof devMode === 'object' ? devMode : {}),
|
|
10
|
+
implement,
|
|
11
|
+
lazy: false,
|
|
12
|
+
skipCommonRuntimeInjection: false
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -9,6 +9,8 @@ import type { VitePluginTaroOptions } from '../../../../options.ts'
|
|
|
9
9
|
import { once } from '../../../utils/once.ts'
|
|
10
10
|
import { resolvePackageFile } from '../../../utils/packages.ts'
|
|
11
11
|
import { appShellFileName } from '../module.ts'
|
|
12
|
+
import { createWxDevMode } from './create-wx-dev-mode.ts'
|
|
13
|
+
import { emptyOutputDirectory } from './empty-output-directory.ts'
|
|
12
14
|
import {
|
|
13
15
|
type HmrInfo,
|
|
14
16
|
hmrControlPath,
|
|
@@ -244,20 +246,31 @@ export async function createWxDevHost({
|
|
|
244
246
|
})
|
|
245
247
|
|
|
246
248
|
rolldownOptions.experimental ??= {}
|
|
247
|
-
rolldownOptions.experimental.devMode =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
rolldownOptions.experimental.devMode = createWxDevMode(
|
|
250
|
+
rolldownOptions.experimental.devMode,
|
|
251
|
+
await bundleRuntimeSource()
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
const emptyOutputDirectoryPlugin: Plugin = {
|
|
255
|
+
name: 'vpt:wx-empty-output-directory',
|
|
256
|
+
renderStart: {
|
|
257
|
+
order: 'pre',
|
|
258
|
+
// DevEngine bypasses Vite's build-only output preparation. Clear stale files before every complete
|
|
259
|
+
// physical render while retaining the directory watched by WeChat DevTools.
|
|
260
|
+
handler: () => emptyOutputDirectory(server.config.build.outDir)
|
|
261
|
+
}
|
|
253
262
|
}
|
|
254
|
-
|
|
255
263
|
const reportInitialBuildPlugin: Plugin = {
|
|
256
264
|
name: 'vpt:wx-report-initial-build',
|
|
257
265
|
buildEnd: settleInitialBuild
|
|
258
266
|
}
|
|
259
267
|
|
|
260
|
-
rolldownOptions.plugins = [
|
|
268
|
+
rolldownOptions.plugins = [
|
|
269
|
+
emptyOutputDirectoryPlugin,
|
|
270
|
+
rolldownOptions.plugins,
|
|
271
|
+
reportInitialBuildPlugin,
|
|
272
|
+
createViteReporter(server)
|
|
273
|
+
]
|
|
261
274
|
disableViteOxcSourcemap(rolldownOptions.plugins)
|
|
262
275
|
return rolldownOptions
|
|
263
276
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
/** Empties an output directory without replacing the directory itself or deleting Git metadata. */
|
|
5
|
+
export async function emptyOutputDirectory(directory: string): Promise<void> {
|
|
6
|
+
await fs.mkdir(directory, { recursive: true })
|
|
7
|
+
const entries = await fs.readdir(directory)
|
|
8
|
+
|
|
9
|
+
await Promise.all(
|
|
10
|
+
entries
|
|
11
|
+
.filter((entry) => entry !== '.git')
|
|
12
|
+
.map((entry) => fs.rm(path.join(directory, entry), { force: true, recursive: true }))
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PluginObj, types } from '@babel/core'
|
|
2
2
|
import type { Plugin } from 'vite'
|
|
3
3
|
import { memoize } from '../../../utils/memoize.ts'
|
|
4
4
|
import { transformWithBabel } from '../../../utils/transform.ts'
|
|
@@ -81,7 +81,7 @@ export function createWxReactRefreshTransforms(): Plugin[] {
|
|
|
81
81
|
* explicit member access is precise. The hook itself is created on `global` by the dev
|
|
82
82
|
* runtime chunk (see dev-runtime.ts).
|
|
83
83
|
*/
|
|
84
|
-
function rewriteReactDevtoolsHookGlobal():
|
|
84
|
+
function rewriteReactDevtoolsHookGlobal(): PluginObj {
|
|
85
85
|
return {
|
|
86
86
|
name: 'vpt:wx-react-devtools-hook-global',
|
|
87
87
|
visitor: {
|
|
@@ -124,7 +124,7 @@ function rewriteReactDevtoolsHookGlobal(): PluginObject {
|
|
|
124
124
|
* replay captures it; the patched commit hooks then track every later mount, including the
|
|
125
125
|
* remounts on re-execution.
|
|
126
126
|
*/
|
|
127
|
-
function injectRefreshGlobalHook():
|
|
127
|
+
function injectRefreshGlobalHook(): PluginObj {
|
|
128
128
|
return {
|
|
129
129
|
name: 'vpt:wx-refresh-global-hook-injection',
|
|
130
130
|
visitor: {
|
|
@@ -153,7 +153,7 @@ function injectRefreshGlobalHook(): PluginObject {
|
|
|
153
153
|
* Only the exact known protocol names are rewritten, one by one, so unrelated `window`
|
|
154
154
|
* accesses are never touched and future protocol additions are deliberate.
|
|
155
155
|
*/
|
|
156
|
-
function rewriteRefreshRuntimeWindowAccess():
|
|
156
|
+
function rewriteRefreshRuntimeWindowAccess(): PluginObj {
|
|
157
157
|
/**
|
|
158
158
|
* Refresh protocol globals that must land on the WeChat `global`:
|
|
159
159
|
* - `__registerBeforePerformReactRefresh`: assigned at module scope; in web, the HMR
|
|
@@ -186,7 +186,7 @@ function rewriteRefreshRuntimeWindowAccess(): PluginObject {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/** Boundary modules: remove the generated `if (!window.$RefreshReg$) throw Error(...)` guard. */
|
|
189
|
-
function removeRefreshPreambleGuard():
|
|
189
|
+
function removeRefreshPreambleGuard(): PluginObj {
|
|
190
190
|
return {
|
|
191
191
|
name: 'vpt:wx-refresh-preamble-guard',
|
|
192
192
|
visitor: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PluginObj, types } from '@babel/core'
|
|
2
2
|
import { resolveChunkReference } from '../../../utils/modules.ts'
|
|
3
3
|
|
|
4
4
|
/** Wraps System.register as an inert CommonJS capsule tuple with canonical final dependency IDs. */
|
|
5
|
-
export function wrapCapsulePlugin(fileName: string):
|
|
5
|
+
export function wrapCapsulePlugin(fileName: string): PluginObj {
|
|
6
6
|
return {
|
|
7
7
|
name: 'vpt:wrap-capsule',
|
|
8
8
|
visitor: {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PluginObj, type PluginTarget, types } from '@babel/core'
|
|
2
2
|
import transformModulesCommonjs from '@babel/plugin-transform-modules-commonjs'
|
|
3
3
|
import type { Rolldown } from 'vite'
|
|
4
4
|
import { resolveChunkReference } from '../../../utils/modules.ts'
|
|
@@ -29,7 +29,7 @@ export function renderNative({
|
|
|
29
29
|
function connectNativeCapsulesPlugin(
|
|
30
30
|
fileName: string,
|
|
31
31
|
chunks: Readonly<Record<string, Rolldown.RenderedChunk>>
|
|
32
|
-
):
|
|
32
|
+
): PluginObj {
|
|
33
33
|
return {
|
|
34
34
|
name: 'vpt:connect-native-capsules',
|
|
35
35
|
visitor: {
|