vite-plugin-taro 0.0.4 → 0.0.6
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 +457 -0
- package/README.md +295 -114
- package/client.d.ts +9 -0
- package/dist/vite/constants.js +7 -0
- package/dist/vite/targets/h5.js +5 -4
- package/dist/vite/targets/wx.js +5 -5
- package/dist/vite/virtual-modules.js +13 -0
- package/dist/vite/vite-plugin-taro.js +3 -3
- package/package.json +10 -30
- package/src/vite/constants.ts +10 -0
- package/src/vite/targets/h5.ts +5 -4
- package/src/vite/targets/wx.ts +5 -5
- package/src/vite/virtual-modules.ts +14 -0
- package/src/vite/vite-plugin-taro.ts +3 -2
- package/src/public/taro.d.ts +0 -2
- /package/dist/{public/taro.js → virtual/api.js} +0 -0
- /package/dist/{public → virtual}/components.js +0 -0
- /package/src/{public/taro.ts → virtual/api.ts} +0 -0
- /package/src/{public → virtual}/components.ts +0 -0
|
@@ -3,6 +3,7 @@ import { createTailwindcssPlugins } from './tailwindcss.js';
|
|
|
3
3
|
import { createH5SupportPlugins, createH5ViteConfig, createWebIndexHtmlTags, isH5VirtualModuleId, loadH5VirtualModule } from './targets/h5.js';
|
|
4
4
|
import { createWxViteConfig, emitWechatAssets, emitWechatImplicitChunksForVirtualApp, isWxVirtualModuleId, loadWxVirtualModule } from './targets/wx.js';
|
|
5
5
|
import { stripVirtualPrefix, toImportPath } from './utils.js';
|
|
6
|
+
import { resolvePublicVirtualModuleId } from './virtual-modules.js';
|
|
6
7
|
/**
|
|
7
8
|
* Creates the Vite/Rolldown plugin that emits either WeChat Mini Program files
|
|
8
9
|
* or a Taro Web app using the official Taro runtime packages.
|
|
@@ -38,10 +39,9 @@ function createVitePluginTaroPlugin(context) {
|
|
|
38
39
|
return context.target === 'wx' ? createWxViteConfig(context) : createH5ViteConfig();
|
|
39
40
|
}
|
|
40
41
|
},
|
|
41
|
-
/**
|
|
42
|
+
/** Maps public virtual modules to real proxy files and marks generated entries as virtual modules. */
|
|
42
43
|
resolveId(id) {
|
|
43
|
-
|
|
44
|
-
return `\0${id}`;
|
|
44
|
+
return resolvePublicVirtualModuleId(id) ?? (isWxVirtualModuleId(id) || isH5VirtualModuleId(id) ? `\0${id}` : undefined);
|
|
45
45
|
},
|
|
46
46
|
/** Supplies source code for each virtual entry module. */
|
|
47
47
|
load(id) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Vite 8 plugin for building one React/Taro codebase for WeChat Mini Program and H5 targets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -20,38 +20,18 @@
|
|
|
20
20
|
"import": "./dist/vite.js",
|
|
21
21
|
"default": "./dist/vite.js"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./
|
|
25
|
-
"import": "./dist/public/components.js",
|
|
26
|
-
"default": "./dist/public/components.js"
|
|
27
|
-
},
|
|
28
|
-
"./taro": {
|
|
29
|
-
"types": "./src/public/taro.d.ts",
|
|
30
|
-
"import": "./dist/public/taro.js",
|
|
31
|
-
"default": "./dist/public/taro.js"
|
|
32
|
-
},
|
|
33
|
-
"./shim/h5": {
|
|
34
|
-
"types": "./src/shim/h5.ts",
|
|
35
|
-
"import": "./dist/shim/h5.js",
|
|
36
|
-
"default": "./dist/shim/h5.js"
|
|
37
|
-
},
|
|
38
|
-
"./shim/wx": {
|
|
39
|
-
"types": "./src/shim/wx.ts",
|
|
40
|
-
"import": "./dist/shim/wx.js",
|
|
41
|
-
"default": "./dist/shim/wx.js"
|
|
42
|
-
},
|
|
43
|
-
"./vite": {
|
|
44
|
-
"types": "./src/vite.ts",
|
|
45
|
-
"import": "./dist/vite.js",
|
|
46
|
-
"default": "./dist/vite.js"
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./client.d.ts"
|
|
47
25
|
},
|
|
48
26
|
"./package.json": "./package.json"
|
|
49
27
|
},
|
|
50
28
|
"files": [
|
|
51
29
|
"dist",
|
|
52
30
|
"src",
|
|
31
|
+
"client.d.ts",
|
|
53
32
|
"LICENSE",
|
|
54
|
-
"README.md"
|
|
33
|
+
"README.md",
|
|
34
|
+
"README.en.md"
|
|
55
35
|
],
|
|
56
36
|
"keywords": [
|
|
57
37
|
"vite",
|
|
@@ -67,7 +47,7 @@
|
|
|
67
47
|
"access": "public"
|
|
68
48
|
},
|
|
69
49
|
"engines": {
|
|
70
|
-
"node": "
|
|
50
|
+
"node": ">=22"
|
|
71
51
|
},
|
|
72
52
|
"dependencies": {
|
|
73
53
|
"@babel/core": "^7.29.7",
|
|
@@ -84,8 +64,8 @@
|
|
|
84
64
|
"babel-plugin-transform-taroapi": "^4.2.0",
|
|
85
65
|
"tailwindcss": "^4.3.1",
|
|
86
66
|
"weapp-tailwindcss": "^5.0.13",
|
|
87
|
-
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@4.2.0-react19.
|
|
88
|
-
"@tarojs/react": "npm:vite-plugin-taro-react@4.2.0-react19.
|
|
67
|
+
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@4.2.0-react19.5",
|
|
68
|
+
"@tarojs/react": "npm:vite-plugin-taro-react@4.2.0-react19.5"
|
|
89
69
|
},
|
|
90
70
|
"peerDependencies": {
|
|
91
71
|
"react": "^19.0.0",
|
|
@@ -99,7 +79,7 @@
|
|
|
99
79
|
"vite": "^8.0.16"
|
|
100
80
|
},
|
|
101
81
|
"scripts": {
|
|
102
|
-
"build": "rm -rf dist && tsgo --project tsconfig.json",
|
|
82
|
+
"build": "node ../../scripts/sync-plugin-readme.mjs && rm -rf dist && tsgo --project tsconfig.json",
|
|
103
83
|
"typecheck": "tsgo --project tsconfig.json --noEmit"
|
|
104
84
|
}
|
|
105
85
|
}
|
package/src/vite/constants.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
|
|
3
4
|
export const isProd = process.env.NODE_ENV === 'production'
|
|
4
5
|
|
|
5
6
|
export const nodeRequire = createRequire(import.meta.url)
|
|
7
|
+
|
|
8
|
+
const packageRoot = path.dirname(nodeRequire.resolve('vite-plugin-taro/package.json'))
|
|
9
|
+
|
|
10
|
+
export const h5ShimImportPath = normalizeFileImport(path.join(packageRoot, 'dist/shim/h5.js'))
|
|
11
|
+
export const wxShimImportPath = normalizeFileImport(path.join(packageRoot, 'dist/shim/wx.js'))
|
|
12
|
+
|
|
13
|
+
function normalizeFileImport(filePath: string): string {
|
|
14
|
+
return filePath.replace(/\\/g, '/')
|
|
15
|
+
}
|
package/src/vite/targets/h5.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { types as BabelTypes, NodePath, PluginObj } from '@babel/core'
|
|
|
2
2
|
import babel from '@rolldown/plugin-babel'
|
|
3
3
|
import react from '@vitejs/plugin-react'
|
|
4
4
|
import type { HtmlTagDescriptor, PluginOption, UserConfig } from 'vite'
|
|
5
|
-
import { isProd, nodeRequire } from '../constants.ts'
|
|
5
|
+
import { h5ShimImportPath, isProd, nodeRequire } from '../constants.ts'
|
|
6
6
|
import type { JsonObject, VitePluginTaroBuildContext, VitePluginTaroPageOption } from '../types.ts'
|
|
7
7
|
import { createPageComponentImport } from '../utils.ts'
|
|
8
|
+
import { virtualTaroApiId } from '../virtual-modules.ts'
|
|
8
9
|
|
|
9
10
|
const virtualH5Id = 'virtual:vite-plugin-taro/h5'
|
|
10
11
|
const patchStencilCssOrder = true
|
|
@@ -87,14 +88,14 @@ export function createH5SupportPlugins(): PluginOption[] {
|
|
|
87
88
|
)
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
// Mirrors Taro H5: rewrite default Taro.xxx calls from
|
|
91
|
+
// Mirrors Taro H5: rewrite default Taro.xxx calls from virtual:taro/api to named H5 API imports.
|
|
91
92
|
plugins.push(
|
|
92
93
|
babel({
|
|
93
94
|
plugins: [
|
|
94
95
|
[
|
|
95
96
|
nodeRequire.resolve('babel-plugin-transform-taroapi'),
|
|
96
97
|
{
|
|
97
|
-
packageName:
|
|
98
|
+
packageName: virtualTaroApiId,
|
|
98
99
|
definition: nodeRequire(nodeRequire.resolve('@tarojs/plugin-platform-h5/dist/definition.json'))
|
|
99
100
|
}
|
|
100
101
|
]
|
|
@@ -180,7 +181,7 @@ import {
|
|
|
180
181
|
createRouter,
|
|
181
182
|
handleAppMount,
|
|
182
183
|
window
|
|
183
|
-
} from
|
|
184
|
+
} from ${JSON.stringify(h5ShimImportPath)}
|
|
184
185
|
import React from 'react'
|
|
185
186
|
import ReactDOM from 'react-dom/client'
|
|
186
187
|
import AppComponent from '${context.appComponentImport}'
|
package/src/vite/targets/wx.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path'
|
|
|
2
2
|
import { recursiveMerge } from '@tarojs/helper'
|
|
3
3
|
import { Weapp as WechatPlatform } from '@tarojs/plugin-platform-weapp'
|
|
4
4
|
import type { UserConfig } from 'vite'
|
|
5
|
-
import { isProd, nodeRequire } from '../constants.ts'
|
|
5
|
+
import { isProd, nodeRequire, wxShimImportPath } from '../constants.ts'
|
|
6
6
|
import type { JsonObject, VitePluginTaroBuildContext, VitePluginTaroPageOption } from '../types.ts'
|
|
7
7
|
import { createPageComponentImport, normalizeModuleId } from '../utils.ts'
|
|
8
8
|
|
|
@@ -38,7 +38,7 @@ export function loadWxVirtualModule(cleanId: string, context: VitePluginTaroBuil
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const taroWechatComponentsReactPath = nodeRequire.resolve('@tarojs/plugin-platform-weapp/dist/components-react')
|
|
41
|
-
const vitePluginTaroSourcePath = normalizeModuleId(path.dirname(nodeRequire.resolve('vite-plugin-taro
|
|
41
|
+
const vitePluginTaroSourcePath = normalizeModuleId(path.dirname(nodeRequire.resolve('vite-plugin-taro')))
|
|
42
42
|
const taroVersion = String(nodeRequire('@tarojs/runtime/package.json').version)
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -210,7 +210,7 @@ export function emitWechatImplicitChunksForVirtualApp(
|
|
|
210
210
|
export function createWxAppEntry(context: VitePluginTaroBuildContext): string {
|
|
211
211
|
const wechatAppConfigCode = JSON.stringify(context.appConfig)
|
|
212
212
|
|
|
213
|
-
return `import { createReactApp, ReactDOM } from
|
|
213
|
+
return `import { createReactApp, ReactDOM } from ${JSON.stringify(wxShimImportPath)}
|
|
214
214
|
import React from 'react'
|
|
215
215
|
import AppComponent from '${context.appComponentImport}'
|
|
216
216
|
|
|
@@ -227,7 +227,7 @@ App(createReactApp(AppComponent, React, ReactDOM, appConfig))
|
|
|
227
227
|
export function createWxPageEntry(pageOption: VitePluginTaroPageOption): string {
|
|
228
228
|
const wechatPageConfigCode = JSON.stringify(pageOption.config)
|
|
229
229
|
const pageComponentImport = createPageComponentImport(pageOption.path)
|
|
230
|
-
return `import { createPageConfig } from
|
|
230
|
+
return `import { createPageConfig } from ${JSON.stringify(wxShimImportPath)}
|
|
231
231
|
import PageComponent from '${pageComponentImport}'
|
|
232
232
|
|
|
233
233
|
const pageConfig = ${wechatPageConfigCode}
|
|
@@ -247,7 +247,7 @@ Page(taroPageConfig)
|
|
|
247
247
|
* https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/template/comp.ts#L1-L4
|
|
248
248
|
*/
|
|
249
249
|
export function createWxCompEntry(): string {
|
|
250
|
-
return `import { createRecursiveComponentConfig } from
|
|
250
|
+
return `import { createRecursiveComponentConfig } from ${JSON.stringify(wxShimImportPath)}
|
|
251
251
|
|
|
252
252
|
Component(createRecursiveComponentConfig())
|
|
253
253
|
`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { nodeRequire } from './constants.ts'
|
|
3
|
+
|
|
4
|
+
export const virtualTaroApiId = 'virtual:taro/api'
|
|
5
|
+
export const virtualTaroComponentsId = 'virtual:taro/components'
|
|
6
|
+
|
|
7
|
+
const packageRoot = path.dirname(nodeRequire.resolve('vite-plugin-taro/package.json'))
|
|
8
|
+
const virtualTaroApiResolvedId = path.join(packageRoot, 'dist/virtual/api.js')
|
|
9
|
+
const virtualTaroComponentsResolvedId = path.join(packageRoot, 'dist/virtual/components.js')
|
|
10
|
+
|
|
11
|
+
export function resolvePublicVirtualModuleId(id: string): string | undefined {
|
|
12
|
+
if (id === virtualTaroApiId) return virtualTaroApiResolvedId
|
|
13
|
+
if (id === virtualTaroComponentsId) return virtualTaroComponentsResolvedId
|
|
14
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from './targets/wx.ts'
|
|
18
18
|
import type { VitePluginTaroBuildContext, VitePluginTaroOptions } from './types.ts'
|
|
19
19
|
import { stripVirtualPrefix, toImportPath } from './utils.ts'
|
|
20
|
+
import { resolvePublicVirtualModuleId } from './virtual-modules.ts'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Creates the Vite/Rolldown plugin that emits either WeChat Mini Program files
|
|
@@ -58,9 +59,9 @@ function createVitePluginTaroPlugin(context: VitePluginTaroBuildContext): Plugin
|
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
|
|
61
|
-
/**
|
|
62
|
+
/** Maps public virtual modules to real proxy files and marks generated entries as virtual modules. */
|
|
62
63
|
resolveId(id) {
|
|
63
|
-
|
|
64
|
+
return resolvePublicVirtualModuleId(id) ?? (isWxVirtualModuleId(id) || isH5VirtualModuleId(id) ? `\0${id}` : undefined)
|
|
64
65
|
},
|
|
65
66
|
|
|
66
67
|
/** Supplies source code for each virtual entry module. */
|
package/src/public/taro.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|