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

Set __file to file basename in production #1368

Merged
Merged
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: 9 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,15 @@ var component = normalizer(
code += `\n` + genHotReloadCode(id, hasFunctional, templateRequest)
}

// Expose filename. This is used by the devtools and vue runtime warnings.
if (!isProduction) {
code += `\ncomponent.options.__file = ${JSON.stringify(rawShortFilePath)}`
}
// Expose filename. This is used by the devtools and Vue runtime warnings.
code += `\ncomponent.options.__file = ${
isProduction
// For security reasons, only expose the file's basename in production.
? JSON.stringify(filename)
// Expose the file's full path in development, so that it can be opened
// from the devtools.
: JSON.stringify(rawShortFilePath)
}`

code += `\nexport default component.exports`
// console.log(code)
Expand Down
17 changes: 16 additions & 1 deletion test/advanced.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('inherit queries on files', done => {
})
})

test('expose filename', done => {
test('expose file path as __file outside production', done => {
mockBundleAndRun({
entry: 'basic.vue'
}, ({ module }) => {
Expand All @@ -55,6 +55,21 @@ test('expose filename', done => {
})
})

test('expose file basename as __file in production', done => {
const origNodeEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
mockBundleAndRun(
{
entry: 'basic.vue'
},
({ module }) => {
expect(module.__file).toBe('basic.vue')
process.env.NODE_ENV = origNodeEnv
done()
}
)
})

test('source map', done => {
bundle({
entry: 'basic.vue',
Expand Down
Loading