vite-plugin-taro 0.5.12 → 0.5.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/dist/node/plugins/client/client-taro.d.ts +1 -1
- package/dist/node/plugins/client/client-taro.js +2 -1
- package/dist/node/plugins/h5/create-stencil-client-adapter.d.ts +1 -1
- package/dist/node/plugins/h5/create-stencil-client-adapter.js +2 -1
- package/dist/node/plugins/h5/plugins.js +22 -1
- package/dist/node/plugins/h5/resolver/module-resolver.js +2 -1
- package/dist/node/plugins/tailwind/tailwind-css.d.ts +1 -0
- package/dist/node/plugins/tailwind/tailwind-css.js +3 -0
- package/dist/node/plugins/wx/dev/create-hmr-results-stream.d.ts +23 -0
- package/dist/node/plugins/wx/dev/create-hmr-results-stream.js +57 -0
- package/dist/node/plugins/wx/dev/create-style-capture.d.ts +42 -0
- package/dist/node/plugins/wx/dev/create-style-capture.js +125 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +5 -1
- package/dist/node/plugins/wx/dev/dev-host.js +170 -47
- package/dist/node/plugins/wx/dev/hmr-files.d.ts +10 -0
- package/dist/node/plugins/wx/dev/hmr-files.js +12 -0
- package/dist/node/plugins/wx/dev/host-actions.d.ts +16 -0
- package/dist/node/plugins/wx/dev/host-actions.js +58 -0
- package/dist/node/plugins/wx/dev/patch-publisher.d.ts +2 -2
- package/dist/node/plugins/wx/dev/patch-publisher.js +17 -1
- package/dist/node/plugins/wx/dev/plugins.d.ts +25 -2
- package/dist/node/plugins/wx/dev/plugins.js +61 -9
- package/dist/node/plugins/wx/dev/react-refresh.js +6 -2
- package/dist/node/plugins/wx/dev/runtime-reports.d.ts +27 -0
- package/dist/node/plugins/wx/dev/runtime-reports.js +45 -0
- package/dist/node/plugins/wx/dev/wx-dev-options.d.ts +10 -5
- package/dist/node/plugins/wx/dev/wx-dev-options.js +47 -24
- package/dist/node/plugins/wx/module.d.ts +1 -1
- package/dist/node/plugins/wx/module.js +2 -1
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +2 -1
- package/dist/node/plugins/wx/native/create-native-component-output.js +2 -0
- package/dist/node/plugins/wx/native/native-component-assets.d.ts +1 -1
- package/dist/node/plugins/wx/native/native-component-assets.js +3 -3
- package/dist/node/plugins/wx/native/native-component-interface.js +2 -1
- package/dist/node/plugins/wx/output/files.d.ts +1 -1
- package/dist/node/plugins/wx/output/files.js +6 -1
- package/dist/node/plugins/wx/plugins.js +13 -6
- package/dist/node/plugins/wx/resolve/resolver.d.ts +2 -1
- package/dist/node/plugins/wx/resolve/resolver.js +34 -19
- package/dist/node/plugins/wx/styles/plugins.d.ts +3 -0
- package/dist/node/plugins/wx/styles/plugins.js +111 -0
- package/dist/node/plugins/wx/styles/transform-wx-style.d.ts +8 -0
- package/dist/node/plugins/wx/styles/transform-wx-style.js +9 -0
- package/dist/node/plugins/wx/styles/utils.d.ts +39 -0
- package/dist/node/plugins/wx/styles/utils.js +95 -0
- package/dist/node/utils/modules.d.ts +1 -1
- package/dist/node/utils/modules.js +4 -3
- package/dist/node/utils/packages.js +2 -2
- package/dist/node/utils/vite.d.ts +17 -0
- package/dist/node/utils/vite.js +43 -0
- package/dist/node/vite-plugin.js +0 -2
- package/package.json +4 -3
- package/src/node/plugins/client/client-taro.ts +2 -2
- package/src/node/plugins/h5/create-stencil-client-adapter.ts +2 -2
- package/src/node/plugins/h5/plugins.ts +22 -1
- package/src/node/plugins/h5/resolver/module-resolver.ts +2 -1
- package/src/node/plugins/tailwind/tailwind-css.ts +4 -0
- package/src/node/plugins/wx/dev/create-hmr-results-stream.ts +71 -0
- package/src/node/plugins/wx/dev/create-style-capture.ts +179 -0
- package/src/node/plugins/wx/dev/dev-host.ts +198 -63
- package/src/node/plugins/wx/dev/hmr-files.ts +13 -0
- package/src/node/plugins/wx/dev/host-actions.ts +88 -0
- package/src/node/plugins/wx/dev/patch-publisher.ts +19 -2
- package/src/node/plugins/wx/dev/plugins.ts +67 -10
- package/src/node/plugins/wx/dev/react-refresh.ts +6 -2
- package/src/node/plugins/wx/dev/runtime-reports.ts +70 -0
- package/src/node/plugins/wx/dev/wx-dev-options.ts +53 -32
- package/src/node/plugins/wx/module.ts +2 -4
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +2 -1
- package/src/node/plugins/wx/native/create-native-component-output.ts +2 -0
- package/src/node/plugins/wx/native/native-component-assets.ts +3 -4
- package/src/node/plugins/wx/native/native-component-interface.ts +2 -1
- package/src/node/plugins/wx/output/files.ts +6 -1
- package/src/node/plugins/wx/plugins.ts +16 -6
- package/src/node/plugins/wx/resolve/resolver.ts +36 -19
- package/src/node/plugins/wx/styles/plugins.ts +125 -0
- package/src/node/plugins/wx/styles/transform-wx-style.ts +11 -0
- package/src/node/plugins/wx/styles/utils.ts +119 -0
- package/src/node/utils/modules.ts +4 -3
- package/src/node/utils/packages.ts +2 -2
- package/src/node/utils/vite.ts +67 -0
- package/src/node/vite-plugin.ts +0 -2
- package/dist/node/plugins/css/plugins.d.ts +0 -4
- package/dist/node/plugins/css/plugins.js +0 -119
- package/dist/node/plugins/wx/dev/create-wx-dev-mode.d.ts +0 -6
- package/dist/node/plugins/wx/dev/create-wx-dev-mode.js +0 -9
- package/dist/node/utils/serialized-task-queue.d.ts +0 -13
- package/dist/node/utils/serialized-task-queue.js +0 -25
- package/src/node/plugins/css/plugins.ts +0 -135
- package/src/node/plugins/wx/dev/create-wx-dev-mode.ts +0 -14
- package/src/node/utils/serialized-task-queue.ts +0 -32
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { createStyleHandler } from '@weapp-tailwindcss/postcss'
|
|
3
|
-
import type { Plugin, PluginOption, Rolldown } from 'vite'
|
|
4
|
-
import { WeappTailwindcss } from 'weapp-tailwindcss/vite'
|
|
5
|
-
import type { VitePluginTaroTarget } from '../../../options.ts'
|
|
6
|
-
import { packageRequire } from '../../utils/packages.ts'
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* CSS output order for WX:
|
|
10
|
-
*
|
|
11
|
-
* weapp-tailwindcss output hooks
|
|
12
|
-
* → vpt:wx-style-finalizer
|
|
13
|
-
* → vpt:wx native companion emission
|
|
14
|
-
*
|
|
15
|
-
* All three generateBundle hooks retain hook-level `order: 'post'` and therefore execute in registration order. The
|
|
16
|
-
* upstream plugin normally also uses plugin-level `enforce: 'post'`, which would move it behind both VPT plugins and
|
|
17
|
-
* break this sequence. `alignWxGenerateBundleOrder` removes only that broader phase from upstream output hooks.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// Tailwind belongs to VPT, not necessarily to the application. Resolving from VPT keeps strict package managers and
|
|
21
|
-
// bundled development from looking for Tailwind in the application's node_modules.
|
|
22
|
-
const tailwindcssBasedir = path.dirname(packageRequire.resolve('tailwindcss/package.json'))
|
|
23
|
-
|
|
24
|
-
// Both upstream generation and VPT's final whole-file pass use one conversion policy. If these options diverge, the
|
|
25
|
-
// second pass can preserve browser units or reinterpret syntax that the first pass generated.
|
|
26
|
-
const wxStyleOptions = {
|
|
27
|
-
cssCalc: false,
|
|
28
|
-
autoprefixer: false,
|
|
29
|
-
rem2rpx: true,
|
|
30
|
-
px2rpx: true
|
|
31
|
-
} as const
|
|
32
|
-
|
|
33
|
-
// The handler is immutable and reusable across builds; only each emitted asset's source is replaced.
|
|
34
|
-
const transformWxStyle = createStyleHandler(wxStyleOptions)
|
|
35
|
-
|
|
36
|
-
/** Creates the target-aware Tailwind pipeline. */
|
|
37
|
-
export function createCssPlugins(target: VitePluginTaroTarget): PluginOption[] {
|
|
38
|
-
const wx = target === 'wx'
|
|
39
|
-
|
|
40
|
-
const tailwindPlugins =
|
|
41
|
-
WeappTailwindcss({
|
|
42
|
-
// VPT is a custom Vite compiler. Using Taro's adapter would import Taro-specific CSS ownership rules.
|
|
43
|
-
appType: 'weapp-vite',
|
|
44
|
-
// WX generation rewrites Tailwind's split package imports before Vite tries to resolve them in the app.
|
|
45
|
-
// Without this, strict workspaces fail on imports such as `tailwindcss/theme.css`.
|
|
46
|
-
rewriteCssImports: wx,
|
|
47
|
-
platform: wx ? 'weapp' : 'web',
|
|
48
|
-
tailwindcssBasedir,
|
|
49
|
-
generator: {
|
|
50
|
-
target: wx ? 'weapp' : 'web'
|
|
51
|
-
},
|
|
52
|
-
cssOptions: {
|
|
53
|
-
...wxStyleOptions,
|
|
54
|
-
// Browser output still needs vendor prefixes; WXSS does not support or need that browser pass.
|
|
55
|
-
autoprefixer: !wx
|
|
56
|
-
},
|
|
57
|
-
logLevel: 'warn'
|
|
58
|
-
}) ?? []
|
|
59
|
-
|
|
60
|
-
return [
|
|
61
|
-
...(wx ? tailwindPlugins.map(alignWxGenerateBundleOrder) : tailwindPlugins),
|
|
62
|
-
wx ? createWxStyleFinalizer() : undefined
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Finalizes the one global stylesheet after upstream Tailwind generation.
|
|
68
|
-
*
|
|
69
|
-
* `cssCodeSplit: false` makes the compiler style global, but upstream can name it `.css` or `.wxss` depending on build
|
|
70
|
-
* mode. This hook converts its complete final contents once and gives it the root `app.wxss` identity required by
|
|
71
|
-
* WeChat. Running earlier loses CSS from dynamic chunks; running after native companion emission would also see Page
|
|
72
|
-
* and native-component WXSS files that must remain opaque.
|
|
73
|
-
*/
|
|
74
|
-
function createWxStyleFinalizer(): Plugin {
|
|
75
|
-
return {
|
|
76
|
-
name: 'vpt:wx-style-finalizer',
|
|
77
|
-
generateBundle: {
|
|
78
|
-
order: 'post',
|
|
79
|
-
async handler(_, bundle) {
|
|
80
|
-
const styles = Object.values(bundle).filter(isStyleAsset)
|
|
81
|
-
// More than one compiler style means cssCodeSplit was re-enabled. Choosing one would silently lose CSS.
|
|
82
|
-
if (styles.length > 1) {
|
|
83
|
-
throw new Error('WX builds require one global compiler-emitted stylesheet')
|
|
84
|
-
}
|
|
85
|
-
// CSS is optional; applications without styles do not need an empty app.wxss.
|
|
86
|
-
if (styles.length === 0) return
|
|
87
|
-
|
|
88
|
-
const [style] = styles
|
|
89
|
-
const source = typeof style.source === 'string' ? style.source : new TextDecoder().decode(style.source)
|
|
90
|
-
// generateBundle exposes the final asset as mutable so conversion and native placement remain atomic.
|
|
91
|
-
// Without the compatibility pass, browser-only selectors, escaped classes, rem and @property can reach
|
|
92
|
-
// WeChat. Without the rename, bundled development writes paths such as src/app.wxss, which WeChat does
|
|
93
|
-
// not load as the application's global stylesheet.
|
|
94
|
-
style.source = (await transformWxStyle(source)).css
|
|
95
|
-
style.fileName = 'app.wxss'
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Adapts upstream plugin descriptors without mutating `weapp-tailwindcss` or patching node_modules.
|
|
103
|
-
*
|
|
104
|
-
* Vite first groups whole plugins by `enforce`, then orders individual hooks. Upstream's output plugins specify both
|
|
105
|
-
* `enforce: 'post'` and `generateBundle.order: 'post'`. The plugin-level phase overrides their earlier registration and
|
|
106
|
-
* places them after VPT's normal plugins, so VPT observes incomplete CSS. Making all of VPT post-enforced would fix that
|
|
107
|
-
* one hook while unnecessarily reordering resolution and transforms.
|
|
108
|
-
*
|
|
109
|
-
* For upstream plugins that actually own generateBundle, clone the descriptor without plugin-level enforcement. Keep
|
|
110
|
-
* hook-level `order: 'post'`: it still waits for ordinary bundle generation, while registration order becomes the sole
|
|
111
|
-
* tie-breaker between upstream generation, VPT finalization and native output. H5 descriptors remain untouched.
|
|
112
|
-
*/
|
|
113
|
-
function alignWxGenerateBundleOrder(pluginOption: PluginOption): PluginOption {
|
|
114
|
-
// PluginOption permits nested arrays. Preserve their shape while adapting every concrete plugin recursively.
|
|
115
|
-
if (Array.isArray(pluginOption)) return pluginOption.map(alignWxGenerateBundleOrder)
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
!pluginOption ||
|
|
119
|
-
typeof pluginOption !== 'object' ||
|
|
120
|
-
!('enforce' in pluginOption) ||
|
|
121
|
-
pluginOption.enforce !== 'post' ||
|
|
122
|
-
!('generateBundle' in pluginOption) ||
|
|
123
|
-
pluginOption.generateBundle === undefined
|
|
124
|
-
) {
|
|
125
|
-
return pluginOption
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Clone rather than mutate: upstream may retain or reuse the descriptor returned by its factory.
|
|
129
|
-
return { ...pluginOption, enforce: undefined }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Selects only the compiler stylesheet; native WXSS assets are emitted by the later WX hook. */
|
|
133
|
-
function isStyleAsset(output: Rolldown.OutputBundle[string]): output is Rolldown.OutputAsset {
|
|
134
|
-
return output.type === 'asset' && /\.(?:css|wxss)$/.test(output.fileName)
|
|
135
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/** Runs asynchronous tasks in insertion order without letting one failure block later work. */
|
|
2
|
-
export class SerializedTaskQueue {
|
|
3
|
-
/** Mutable promise tail confines ordering state to this queue. */
|
|
4
|
-
private tail: Promise<void> = Promise.resolve()
|
|
5
|
-
private readonly reportError: (operation: string, error: unknown) => void
|
|
6
|
-
|
|
7
|
-
constructor(reportError: (operation: string, error: unknown) => void) {
|
|
8
|
-
this.reportError = reportError
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Schedules a background task and reports its failure. */
|
|
12
|
-
enqueue(operation: string, task: () => void | PromiseLike<void>): void {
|
|
13
|
-
void this.run(task).catch((error) => {
|
|
14
|
-
this.reportError(operation, error)
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Schedules a task whose result and failure belong to the caller. */
|
|
19
|
-
run<Result>(task: () => Result | PromiseLike<Result>): Promise<Result> {
|
|
20
|
-
const result = this.tail.then(task)
|
|
21
|
-
this.tail = result.then(
|
|
22
|
-
() => undefined,
|
|
23
|
-
() => undefined
|
|
24
|
-
)
|
|
25
|
-
return result
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Waits for every task that was queued when this method was called. */
|
|
29
|
-
async waitForIdle(): Promise<void> {
|
|
30
|
-
await this.tail
|
|
31
|
-
}
|
|
32
|
-
}
|