Skip to content

Commit 56c3637

Browse files
committed
feat: disabled comment
1 parent 811cb32 commit 56c3637

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const MODULE_NAME = 'vite-plugin-components'
22
export const RESOLVER_EXT = '.vite-plugin-components'
3+
export const DISABLE_COMMENT = '/* vite-plugin-components disabled */'

src/transforms/vueScript.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Transform } from 'vite'
22
import Debug from 'debug'
33
import { Context } from '../context'
4-
import { RESOLVER_EXT } from '../constants'
4+
import { DISABLE_COMMENT, RESOLVER_EXT } from '../constants'
55

66
const debug = Debug('vite-plugin-components:transform:script')
77

@@ -18,17 +18,20 @@ export function VueScriptTransformer(ctx: Context): Transform {
1818
&& !query.type
1919
},
2020
transform({ code, path, isBuild }) {
21+
if (code.includes(DISABLE_COMMENT))
22+
return code
23+
2124
const filepath = ctx.normalizePath(ctx.relative(path))
2225
debug(filepath)
2326

24-
const lines = code.split('\n')
27+
const lines = code.trim().split('\n')
2528

2629
// tail is the export expression, should insert before it
2730
const tail = lines.pop()!
2831

2932
const entry = isBuild ? 'script' : '__script'
3033

31-
if (!code.includes(`export default ${entry}`))
34+
if (tail !== `export default ${entry}`)
3235
return code
3336

3437
// import a component resolver which is generated by the plugin

0 commit comments

Comments
 (0)