Skip to content

fix(babel-preset-app): multiPage repo add option entryFileList #3470

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

Merged
merged 1 commit into from
Feb 28, 2019
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
6 changes: 6 additions & 0 deletions packages/@vue/babel-preset-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ Set to `false` to disable JSX support.
- Default: `false`.

Setting this to `true` will generate code that is more performant but less spec-compliant.

### entryFiles

- Default: `[]`

Multi page repo use entryFiles to ensure inject polyfills to all entry file.
4 changes: 3 additions & 1 deletion packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module.exports = (context, options = {}) => {
forceAllTransforms,
decoratorsBeforeExport,
decoratorsLegacy,
// entry file list
entryFiles,

// Undocumented option of @babel/plugin-transform-runtime.
// When enabled, an absolute path is used when importing a runtime helper atfer tranforming.
Expand Down Expand Up @@ -103,7 +105,7 @@ module.exports = (context, options = {}) => {
ignoreBrowserslistConfig,
configPath
})
plugins.push([require('./polyfillsPlugin'), { polyfills }])
plugins.push([require('./polyfillsPlugin'), { polyfills, entryFiles }])
} else {
polyfills = []
}
Expand Down
12 changes: 8 additions & 4 deletions packages/@vue/babel-preset-app/polyfillsPlugin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// add polyfill imports to the first file encountered.
module.exports = ({ types }) => {
module.exports = ({ types }, { entryFiles = [] }) => {
let entryFile
return {
name: 'vue-cli-inject-polyfills',
visitor: {
Program (path, state) {
if (!entryFile) {
entryFile = state.filename
} else if (state.filename !== entryFile) {
if (entryFiles.length === 0) {
if (!entryFile) {
entryFile = state.filename
} else if (state.filename !== entryFile) {
return
}
} else if (!entryFiles.includes(state.filename)) {
return
}

Expand Down