Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 5c1dffb

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 already define `name` property so `__file` is not required.
1 parent 5fb30ce commit 5c1dffb

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+
const exposeFilename =
167+
typeof opts.exposeFilename === 'boolean' ? opts.exposeFilename : false
157168
delete opts.beforeAssemble
158169
delete opts.css
170+
delete opts.exposeFilename
159171
delete opts.blackListCustomBlocks
160172
delete opts.whiteListCustomBlocks
161173
delete opts.defaultLang
@@ -171,9 +183,11 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
171183
},
172184
...opts.template
173185
} as any
186+
174187
if (opts.template && typeof opts.template.isProduction === 'undefined') {
175188
opts.template.isProduction = isProduction
176189
}
190+
177191
const compiler = createDefaultCompiler(opts)
178192
const descriptors = new Map<string, SFCDescriptor>()
179193

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

230244
async transform(source: string, filename: string) {
231245
if (isVue(filename)) {
246+
// Create deep copy to prevent issue during watching changes.
232247
const descriptor: 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy