Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit5c1dffb

Browse files
committed
feat: Add exposeFilename to control __file property
The `exposeFilename` option is opt-in (defaults to `false`) as rollup-plugin-vue is mainly used to compile libraries and most libraries alreadydefine `name` property so `__file` is not required.
1 parent5fb30ce commit5c1dffb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export interface VuePluginOptions {
8383
* ```
8484
*/
8585
css?:boolean
86+
/**
87+
* Expose filename in __file property.
88+
*@default `false`
89+
*@example
90+
* ```js
91+
* VuePlugin({ exposeFilename: true })
92+
* ```
93+
*/
94+
exposeFilename?:boolean
8695
compiler?:VueTemplateCompiler
8796
compilerParseOptions?:VueTemplateCompilerParseOptions
8897
sourceRoot?:string
@@ -154,8 +163,11 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
154163
opts.beforeAssemble||
155164
((d:DescriptorCompileResult):DescriptorCompileResult=>d)
156165

166+
constexposeFilename=
167+
typeofopts.exposeFilename==='boolean' ?opts.exposeFilename :false
157168
deleteopts.beforeAssemble
158169
deleteopts.css
170+
deleteopts.exposeFilename
159171
deleteopts.blackListCustomBlocks
160172
deleteopts.whiteListCustomBlocks
161173
deleteopts.defaultLang
@@ -171,9 +183,11 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
171183
},
172184
...opts.template
173185
}asany
186+
174187
if(opts.template&&typeofopts.template.isProduction==='undefined'){
175188
opts.template.isProduction=isProduction
176189
}
190+
177191
constcompiler=createDefaultCompiler(opts)
178192
constdescriptors=newMap<string,SFCDescriptor>()
179193

@@ -229,6 +243,7 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
229243

230244
asynctransform(source:string,filename:string){
231245
if(isVue(filename)){
246+
// Create deep copy to prevent issue during watching changes.
232247
constdescriptor:SFCDescriptor=JSON.parse(
233248
JSON.stringify(
234249
parse({
@@ -298,11 +313,16 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
298313
'script'
299314
)}'
300315
export default script
316+
${
317+
exposeFilename
318+
?`
301319
// For security concerns, we use only base name in production mode. See https://github.com/vuejs/rollup-plugin-vue/issues/258
302320
script.__file =${
303321
isProduction
304322
?JSON.stringify(path.basename(filename))
305323
:JSON.stringify(filename)
324+
}`
325+
:''
306326
}
307327
`
308328
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp