@vobs/vite-plugin 1.0.0 → 1.1.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/package.json +3 -3
- package/src/index.test.ts +33 -2
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"LICENSE"
|
|
7
7
|
],
|
|
8
8
|
"name": "@vobs/vite-plugin",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.1.0",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "src/index.ts",
|
|
12
12
|
"types": "src/index.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"parse5": "^8.0.1",
|
|
18
|
-
"@vobs/runtime": "1.
|
|
19
|
-
"@vobs/compiler": "1.
|
|
18
|
+
"@vobs/runtime": "1.1.0",
|
|
19
|
+
"@vobs/compiler": "1.1.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -70,6 +70,35 @@ describe('vobsPlugin', () => {
|
|
|
70
70
|
expect(result.code).not.toContain('import.meta.hot.accept')
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
+
it('生产构建默认剔除组件源码位置,开发构建保留', () => {
|
|
74
|
+
const compile = (plugin: ReturnType<typeof vobsPlugin>, source: string) => {
|
|
75
|
+
const transform = plugin.transform
|
|
76
|
+
if (typeof transform !== 'function') throw new Error('Vobs Vite plugin: 缺少 transform 钩子')
|
|
77
|
+
return transform.call({} as ThisParameterType<typeof transform>,
|
|
78
|
+
source, 'src/App.tsx') as { code: string }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const production = vobsPlugin({ hmr: false })
|
|
82
|
+
;(production.configResolved as (config: unknown) => void)?.({ command: 'build' })
|
|
83
|
+
const productionCode = compile(production, `export function App() { return <Panel /> }`).code
|
|
84
|
+
expect(productionCode).toContain('createComponent')
|
|
85
|
+
expect(productionCode).not.toContain('file:')
|
|
86
|
+
|
|
87
|
+
const development = compile(vobsPlugin(), `export function App() { return <Panel /> }`).code
|
|
88
|
+
expect(development).toContain('file: "src/App.tsx"')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('显式 compiler.sourceLocation 配置优先于生产默认值', () => {
|
|
92
|
+
const plugin = vobsPlugin({ hmr: false, compiler: { sourceLocation: true } })
|
|
93
|
+
const configResolved = plugin.configResolved as ((config: unknown) => void) | undefined
|
|
94
|
+
configResolved?.({ command: 'build' })
|
|
95
|
+
const transform = plugin.transform
|
|
96
|
+
if (typeof transform !== 'function') throw new Error('Vobs Vite plugin: 缺少 transform 钩子')
|
|
97
|
+
const result = transform.call({} as ThisParameterType<typeof transform>,
|
|
98
|
+
`export function App() { return <Panel /> }`, 'src/App.tsx') as { code: string }
|
|
99
|
+
expect(result.code).toContain('file: "src/App.tsx"')
|
|
100
|
+
})
|
|
101
|
+
|
|
73
102
|
it('转换不含 export function 的合法 TSX 模块', () => {
|
|
74
103
|
const plugin = vobsPlugin({ hmr: false })
|
|
75
104
|
const transform = plugin.transform
|
|
@@ -80,7 +109,8 @@ describe('vobsPlugin', () => {
|
|
|
80
109
|
'src/App.tsx'
|
|
81
110
|
) as { code: string }
|
|
82
111
|
|
|
83
|
-
|
|
112
|
+
// 完全静态的 JSX 提升为模板克隆
|
|
113
|
+
expect(result.code).toContain('createTemplate("<main>hello</main>")')
|
|
84
114
|
})
|
|
85
115
|
|
|
86
116
|
it('转换默认箭头导出和带 query 的 TSX 模块', () => {
|
|
@@ -93,7 +123,8 @@ describe('vobsPlugin', () => {
|
|
|
93
123
|
'src/App.tsx?direct'
|
|
94
124
|
) as { code: string }
|
|
95
125
|
|
|
96
|
-
|
|
126
|
+
// 完全静态的 JSX 提升为模板克隆
|
|
127
|
+
expect(result.code).toContain('createTemplate("<main>hello</main>")')
|
|
97
128
|
})
|
|
98
129
|
|
|
99
130
|
it('通过 extractI18n 回调收集静态翻译 key', () => {
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,8 @@ export function vobsPlugin(options: VobsVitePluginOptions = {}): Plugin {
|
|
|
52
52
|
: undefined
|
|
53
53
|
const result = compileWithSourceMap(code, {
|
|
54
54
|
...options.compiler,
|
|
55
|
+
// 生产构建默认剔除组件源码位置(错误定位走 source map);显式配置优先。
|
|
56
|
+
sourceLocation: options.compiler?.sourceLocation ?? !productionBuild,
|
|
55
57
|
filename: id,
|
|
56
58
|
plugins: [
|
|
57
59
|
...(options.compiler?.plugins ?? []),
|