vite-plugin-taro 0.5.1 → 0.5.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/README.en.md +16 -16
- package/README.md +17 -16
- package/dist/node/plugins/client/client-taro.d.ts +4 -2
- package/dist/node/plugins/client/client-taro.js +43 -4
- package/dist/node/plugins/client/inject-taro-framework-apis.d.ts +5 -0
- package/dist/node/plugins/client/inject-taro-framework-apis.js +9 -0
- package/dist/node/plugins/css/plugins.d.ts +1 -3
- package/dist/node/plugins/css/plugins.js +91 -58
- package/dist/node/plugins/h5/create-stencil-client-adapter.d.ts +24 -0
- package/dist/node/plugins/h5/create-stencil-client-adapter.js +80 -0
- package/dist/node/plugins/h5/plugins.js +11 -54
- package/dist/node/plugins/wx/dev/dev-host.js +0 -3
- package/dist/node/plugins/wx/placement/placer.js +1 -2
- package/dist/node/plugins/wx/plugins.js +10 -1
- package/dist/node/vite-plugin.js +1 -1
- package/dist/runtime/client/taro/api.d.ts +2 -3
- package/dist/runtime/client/taro/api.js +9 -8
- package/package.json +12 -12
- package/src/node/plugins/client/client-taro.ts +52 -4
- package/src/node/plugins/client/inject-taro-framework-apis.ts +11 -0
- package/src/node/plugins/css/plugins.ts +89 -53
- package/src/node/plugins/h5/create-stencil-client-adapter.ts +109 -0
- package/src/node/plugins/h5/plugins.ts +11 -76
- package/src/node/plugins/wx/dev/dev-host.ts +0 -3
- package/src/node/plugins/wx/placement/placer.ts +1 -2
- package/src/node/plugins/wx/plugins.ts +10 -1
- package/src/node/vite-plugin.ts +1 -1
- package/src/runtime/client/taro/api.ts +9 -9
- package/dist/node/plugins/wx/dev/publish-wx-dev-style.d.ts +0 -11
- package/dist/node/plugins/wx/dev/publish-wx-dev-style.js +0 -12
- package/src/node/plugins/wx/dev/publish-wx-dev-style.ts +0 -26
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
writeHmrFile
|
|
23
23
|
} from './hmr-files.ts'
|
|
24
24
|
import { PatchPublisher } from './patch-publisher.ts'
|
|
25
|
-
import { publishWxDevStyle } from './publish-wx-dev-style.ts'
|
|
26
25
|
|
|
27
26
|
export type WxDevHost = Readonly<{
|
|
28
27
|
close: () => Promise<void>
|
|
@@ -170,7 +169,6 @@ export async function createWxDevHost({
|
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
return dev(rolldownOptions, rolldownOptions.output, {
|
|
173
|
-
onAdditionalAssets: (output) => publishWxDevStyle(output, server.config.build.outDir),
|
|
174
172
|
onHmrUpdates: async (result) => {
|
|
175
173
|
if (result instanceof Error) {
|
|
176
174
|
logWxError(server.config.logger, 'wx HMR update failed', result)
|
|
@@ -206,7 +204,6 @@ export async function createWxDevHost({
|
|
|
206
204
|
logWxError(server.config.logger, 'wx dev build failed', result)
|
|
207
205
|
return
|
|
208
206
|
}
|
|
209
|
-
await publishWxDevStyle(result, server.config.build.outDir)
|
|
210
207
|
// A fresh build identity per complete physical build; the App runtime reads it
|
|
211
208
|
// from hmr/info.js before any module registers.
|
|
212
209
|
await startFreshBuild()
|
|
@@ -121,8 +121,7 @@ export function createPlacer() {
|
|
|
121
121
|
// into every physical chunk filename; content identity alone is sufficient beneath that root.
|
|
122
122
|
return `${location.root}/assets/[hash].js`
|
|
123
123
|
},
|
|
124
|
-
// Keep generic assets independent of
|
|
125
|
-
// mutation and owns the exact global `app.wxss` identity without confusing native Page companions.
|
|
124
|
+
// Keep generic assets independent of native output identities assigned after bundling.
|
|
126
125
|
assetFileNames: 'assets/[name]-[hash][extname]'
|
|
127
126
|
},
|
|
128
127
|
// Rolldown rejects strict entry signatures when code-splitting groups disable recursive dependency capture.
|
|
@@ -46,8 +46,11 @@ function createWxPlugin(options: VitePluginTaroOptions): Plugin {
|
|
|
46
46
|
|
|
47
47
|
build: {
|
|
48
48
|
modulePreload: false,
|
|
49
|
+
// Mini Program styles are intentionally global. This guarantees one compiler stylesheet for the CSS
|
|
50
|
+
// finalizer; enabling splitting would require Page ownership and must not be silently flattened.
|
|
49
51
|
cssCodeSplit: false,
|
|
50
|
-
//
|
|
52
|
+
// Preserve readable source for the final WX compatibility pass; browser minification can emit syntax
|
|
53
|
+
// unsupported by WeChat and would make the subsequent whole-file conversion harder to reason about.
|
|
51
54
|
cssMinify: false,
|
|
52
55
|
|
|
53
56
|
// No base64 assets: Taro warns on image srcs above ~2KB, and inlined
|
|
@@ -123,6 +126,12 @@ function createWxPlugin(options: VitePluginTaroOptions): Plugin {
|
|
|
123
126
|
},
|
|
124
127
|
|
|
125
128
|
generateBundle: {
|
|
129
|
+
/*
|
|
130
|
+
* This hook is registered after createCssPlugins() and shares hook-level `order: 'post'` with the adapted
|
|
131
|
+
* upstream hooks and VPT style finalizer. Registration order therefore guarantees that app.wxss is complete
|
|
132
|
+
* before native Page/component companions are emitted. Without this order, the CSS finalizer could consume
|
|
133
|
+
* incomplete Tailwind output or mistake native WXSS companions for additional compiler styles.
|
|
134
|
+
*/
|
|
126
135
|
order: 'post',
|
|
127
136
|
async handler(_, bundle) {
|
|
128
137
|
const subpackages = placer.getSubpackages(bundle)
|
package/src/node/vite-plugin.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { createWxTargetPlugins } from './plugins/wx/plugins.ts'
|
|
|
11
11
|
export default function vitePluginTaro(options: VitePluginTaroOptions): PluginOption[] {
|
|
12
12
|
return [
|
|
13
13
|
createConditionalDirectivePlugin(options.target),
|
|
14
|
-
createClientTaroPlugin(),
|
|
14
|
+
createClientTaroPlugin(options.target),
|
|
15
15
|
...createCssPlugins(options.target),
|
|
16
16
|
...react(),
|
|
17
17
|
...(options.target === 'wx' ? createWxTargetPlugins(options) : []),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This physical module is the shared facade, not the generic Taro implementation. Its own `@tarojs/taro` request is
|
|
3
|
+
* resolved by the client plugin to the selected platform APIs, while application requests resolve back to this facade.
|
|
4
|
+
* React's API loader then extends this same object with framework lifecycle hooks.
|
|
5
|
+
*/
|
|
6
|
+
import taro from '@tarojs/taro'
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// @ts-expect-error @tarojs/taro declares export= types, but the facade also exposes its runtime named exports.
|
|
8
|
+
// Re-export platform APIs while preserving object identity for the framework loader's lifecycle assignments.
|
|
9
|
+
// @ts-expect-error @tarojs/taro uses export= types while Rolldown exposes its runtime properties as named exports.
|
|
10
10
|
export * from '@tarojs/taro'
|
|
11
|
-
export default
|
|
11
|
+
export default taro
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type DevOutputFile = Readonly<{
|
|
2
|
-
type: string;
|
|
3
|
-
fileName: string;
|
|
4
|
-
source?: string | Uint8Array;
|
|
5
|
-
}>;
|
|
6
|
-
type DevOutput = Readonly<{
|
|
7
|
-
output: readonly DevOutputFile[];
|
|
8
|
-
}>;
|
|
9
|
-
/** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
|
|
10
|
-
export declare function publishWxDevStyle(output: DevOutput, outDir: string): Promise<void>;
|
|
11
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { adaptWxss } from '../../css/plugins.js';
|
|
4
|
-
/** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
|
|
5
|
-
export async function publishWxDevStyle(output, outDir) {
|
|
6
|
-
// WX disables CSS splitting, so the only non-empty WXSS asset is the application stylesheet; Page companions are empty.
|
|
7
|
-
const globalStyle = output.output.find((file) => file.type === 'asset' && file.fileName.endsWith('.wxss') && file.source && file.source.length > 0);
|
|
8
|
-
if (!globalStyle?.source)
|
|
9
|
-
return;
|
|
10
|
-
const source = typeof globalStyle.source === 'string' ? globalStyle.source : new TextDecoder().decode(globalStyle.source);
|
|
11
|
-
await writeFile(path.join(outDir, 'app.wxss'), await adaptWxss(source));
|
|
12
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { adaptWxss } from '../../css/plugins.ts'
|
|
4
|
-
|
|
5
|
-
type DevOutputFile = Readonly<{
|
|
6
|
-
type: string
|
|
7
|
-
fileName: string
|
|
8
|
-
source?: string | Uint8Array
|
|
9
|
-
}>
|
|
10
|
-
|
|
11
|
-
type DevOutput = Readonly<{
|
|
12
|
-
output: readonly DevOutputFile[]
|
|
13
|
-
}>
|
|
14
|
-
|
|
15
|
-
/** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
|
|
16
|
-
export async function publishWxDevStyle(output: DevOutput, outDir: string): Promise<void> {
|
|
17
|
-
// WX disables CSS splitting, so the only non-empty WXSS asset is the application stylesheet; Page companions are empty.
|
|
18
|
-
const globalStyle = output.output.find(
|
|
19
|
-
(file) => file.type === 'asset' && file.fileName.endsWith('.wxss') && file.source && file.source.length > 0
|
|
20
|
-
)
|
|
21
|
-
if (!globalStyle?.source) return
|
|
22
|
-
|
|
23
|
-
const source =
|
|
24
|
-
typeof globalStyle.source === 'string' ? globalStyle.source : new TextDecoder().decode(globalStyle.source)
|
|
25
|
-
await writeFile(path.join(outDir, 'app.wxss'), await adaptWxss(source))
|
|
26
|
-
}
|