Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "exposeFilename" option to plugin-vue #5535

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/plugin-vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export interface Options {
*/
refTransform?: boolean | string | RegExp | (string | RegExp)[]

/**
* In non-production environments, plugin-vue injects a __file property to components
* for better debugging experience. If the name property is missing in a component,
* Vue will infer it from the __file field to display in console warnings.
* This property is stripped in production builds by default.
* But you may want to retain it if you are developing a component library
* and don't want to bother specifying name in each component.
* Then you can turn this option on.
*
* @default false
*/
exposeFilename?: boolean,

// options to pass on to vue/compiler-sfc
script?: Partial<SFCScriptCompileOptions>
template?: Partial<SFCTemplateCompileOptions>
Expand Down
17 changes: 16 additions & 1 deletion packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export interface Options {
*/
refTransform?: boolean | string | RegExp | (string | RegExp)[]

/**
* In non-production environments, plugin-vue injects a __file property to components
* for better debugging experience. If the name property is missing in a component,
* Vue will infer it from the __file field to display in console warnings.
* This property is stripped in production builds by default.
* But you may want to retain it if you are developing a component library
* and don't want to bother specifying name in each component.
* Then you can turn this option on.
*
* @default false
*/
exposeFilename?: boolean,

/**
* @deprecated the plugin now auto-detects whether it's being invoked for ssr.
*/
Expand All @@ -73,7 +86,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
include = /\.vue$/,
exclude,
customElement = /\.ce\.vue$/,
refTransform = false
refTransform = false,
exposeFilename = false
} = rawOptions

const filter = createFilter(include, exclude)
Expand All @@ -100,6 +114,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
exclude,
customElement,
refTransform,
exposeFilename,
root: process.cwd(),
sourceMap: true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function transformMain(
ssr: boolean,
asCustomElement: boolean
) {
const { devServer, isProduction } = options
const { devServer, isProduction, exposeFilename } = options

// prev descriptor is only set and used for hmr
const prevDescriptor = getPrevDescriptor(filename)
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function transformMain(
if (hasScoped) {
attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)])
}
if (devServer && !isProduction) {
if (devServer && !isProduction || exposeFilename) {
// expose filename during serve for devtools to pickup
attachedProps.push([`__file`, JSON.stringify(filename)])
}
Expand Down