vite-plugin-taro 0.0.2 → 0.0.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/LICENSE +1 -1
- package/README.md +205 -54
- package/dist/public/components.js +1 -1
- package/dist/public/taro.js +8 -10
- package/dist/shim/h5.js +5 -6
- package/dist/shim/wx.js +5 -5
- package/dist/vite/constants.js +3 -0
- package/dist/vite/plugins.js +186 -0
- package/dist/vite/tailwindcss.js +35 -0
- package/dist/vite/targets/h5.js +202 -0
- package/dist/vite/targets/wx.js +364 -0
- package/dist/vite/types.js +1 -0
- package/dist/vite/{utils.d.ts → utils.js} +13 -4
- package/dist/vite/vite-plugin-taro.js +80 -0
- package/dist/vite.js +1 -851
- package/package.json +23 -24
- package/src/public/components.ts +1 -0
- package/src/public/taro.ts +10 -0
- package/src/shim/h5.ts +6 -0
- package/src/shim/wx.ts +6 -0
- package/src/vite/constants.ts +5 -0
- package/src/vite/plugins.ts +218 -0
- package/src/vite/tailwindcss.ts +41 -0
- package/src/vite/targets/h5.ts +230 -0
- package/src/vite/targets/wx.ts +438 -0
- package/{dist/vite/types.d.ts → src/vite/types.ts} +31 -21
- package/src/vite/utils.ts +35 -0
- package/src/vite/vite-plugin-taro.ts +105 -0
- package/src/vite.ts +2 -0
- package/dist/public/components.d.ts +0 -1
- package/dist/public/taro.js.map +0 -1
- package/dist/shim/h5.d.ts +0 -3
- package/dist/shim/wx.d.ts +0 -3
- package/dist/vite/constants.d.ts +0 -2
- package/dist/vite/plugins.d.ts +0 -8
- package/dist/vite/tailwindcss.d.ts +0 -3
- package/dist/vite/targets/h5.d.ts +0 -31
- package/dist/vite/targets/wx.d.ts +0 -74
- package/dist/vite/taro.d.ts +0 -7
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js.map +0 -1
- /package/{dist → src}/public/taro.d.ts +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createVitePluginTaroConditionalDirectivePlugin } from './plugins.js';
|
|
2
|
+
import { createTailwindcssPlugins } from './tailwindcss.js';
|
|
3
|
+
import { createH5SupportPlugins, createH5ViteConfig, createWebIndexHtmlTags, isH5VirtualModuleId, loadH5VirtualModule } from './targets/h5.js';
|
|
4
|
+
import { createWxViteConfig, emitWechatAssets, emitWechatImplicitChunksForVirtualApp, isWxVirtualModuleId, loadWxVirtualModule } from './targets/wx.js';
|
|
5
|
+
import { stripVirtualPrefix, toImportPath } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates the Vite/Rolldown plugin that emits either WeChat Mini Program files
|
|
8
|
+
* or a Taro Web app using the official Taro runtime packages.
|
|
9
|
+
*/
|
|
10
|
+
export default function vitePluginTaro(options) {
|
|
11
|
+
const context = createVitePluginTaroBuildContext(options);
|
|
12
|
+
return [
|
|
13
|
+
createVitePluginTaroConditionalDirectivePlugin(context),
|
|
14
|
+
...createTargetSupportPlugins(context),
|
|
15
|
+
...createTailwindcssPlugins(context),
|
|
16
|
+
createVitePluginTaroPlugin(context)
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
function createTargetSupportPlugins(context) {
|
|
20
|
+
switch (context.target) {
|
|
21
|
+
case 'h5':
|
|
22
|
+
return createH5SupportPlugins();
|
|
23
|
+
default:
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates the vite-plugin-taro plugin that emits H5 or Wx outputs.
|
|
29
|
+
*/
|
|
30
|
+
function createVitePluginTaroPlugin(context) {
|
|
31
|
+
return {
|
|
32
|
+
name: 'vite-plugin-taro',
|
|
33
|
+
enforce: 'post',
|
|
34
|
+
/** Configures Vite/Rolldown for the active target. */
|
|
35
|
+
config: {
|
|
36
|
+
order: 'pre',
|
|
37
|
+
handler: () => {
|
|
38
|
+
return context.target === 'wx' ? createWxViteConfig(context) : createH5ViteConfig();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
/** Marks generated app/page/component entries as virtual modules. */
|
|
42
|
+
resolveId(id) {
|
|
43
|
+
if (isWxVirtualModuleId(id) || isH5VirtualModuleId(id))
|
|
44
|
+
return `\0${id}`;
|
|
45
|
+
},
|
|
46
|
+
/** Supplies source code for each virtual entry module. */
|
|
47
|
+
load(id) {
|
|
48
|
+
const cleanId = stripVirtualPrefix(id);
|
|
49
|
+
emitWechatImplicitChunksForVirtualApp(this, context, cleanId);
|
|
50
|
+
return loadWxVirtualModule(cleanId, context) ?? loadH5VirtualModule(cleanId, context);
|
|
51
|
+
},
|
|
52
|
+
/** Injects the generated Web entry into the app shell before Vite scans HTML imports. */
|
|
53
|
+
transformIndexHtml: {
|
|
54
|
+
order: 'pre',
|
|
55
|
+
handler() {
|
|
56
|
+
return createWebIndexHtmlTags(context);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/** Emits the WeChat JSON/WXML/WXS/WXSS files that are not JS bundle chunks. */
|
|
60
|
+
generateBundle(_, bundle) {
|
|
61
|
+
emitWechatAssets(this, bundle, context);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes user options into the shared data used by both target builders.
|
|
67
|
+
*/
|
|
68
|
+
function createVitePluginTaroBuildContext(options) {
|
|
69
|
+
return {
|
|
70
|
+
target: options.target,
|
|
71
|
+
appComponentImport: toImportPath(options.app),
|
|
72
|
+
pages: options.pages,
|
|
73
|
+
appConfig: {
|
|
74
|
+
...options.appJson,
|
|
75
|
+
pages: options.pages.map((page) => page.path)
|
|
76
|
+
},
|
|
77
|
+
projectConfigJson: options.projectConfigJson,
|
|
78
|
+
sitemapJson: options.sitemapJson
|
|
79
|
+
};
|
|
80
|
+
}
|