Skip to content

Commit d5ed280

Browse files
committed
feat: expose absoluteRuntime option, closes #2807
1 parent 047872c commit d5ed280

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,16 @@ test('jsx options', () => {
125125
expect(code).not.toMatch(`var h = arguments[0]`)
126126
expect(code).toMatch(`return h("div", ["bar"])`)
127127
})
128+
129+
test('disable absoluteRuntime', () => {
130+
const { code } = babel.transformSync(`
131+
const a = [...arr]
132+
`.trim(), {
133+
babelrc: false,
134+
presets: [[preset, {
135+
absoluteRuntime: false
136+
}]]
137+
})
138+
139+
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray"')
140+
})

packages/@vue/babel-preset-app/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ module.exports = (context, options = {}) => {
5151
shippedProposals,
5252
forceAllTransforms,
5353
decoratorsBeforeExport,
54-
decoratorsLegacy
54+
decoratorsLegacy,
55+
56+
// Undocumented option of @babel/plugin-transform-runtime.
57+
// When enabled, an absolute path is used when importing a runtime helper atfer tranforming.
58+
// This ensures the transpiled file always use the runtime version required in this package.
59+
// However, this may cause hash inconsitency if the project is moved to another directory.
60+
// So here we allow user to explicit disable this option if hash consistency is a requirement
61+
// and the runtime version is sure to be correct.
62+
absoluteRuntime = path.dirname(require.resolve('@babel/runtime/package.json'))
5563
} = options
5664

5765
// resolve targets
@@ -146,7 +154,8 @@ module.exports = (context, options = {}) => {
146154
corejs: (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
147155
helpers: useBuiltIns === 'usage',
148156
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
149-
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package.json'))
157+
158+
absoluteRuntime
150159
}])
151160

152161
return {

0 commit comments

Comments
 (0)