diff --git a/packages/nuxt3/src/babel-preset-app/polyfills-plugin.js b/packages/nuxt3/src/babel-preset-app/polyfills-plugin.js deleted file mode 100644 index 8bad5ad5f5..0000000000 --- a/packages/nuxt3/src/babel-preset-app/polyfills-plugin.js +++ /dev/null @@ -1,24 +0,0 @@ -// Add polyfill imports to the first file encountered. -module.exports = ({ _types }) => { - let entryFile - return { - name: 'inject-polyfills', - visitor: { - Program (path, state) { - if (!entryFile) { - entryFile = state.filename - } else if (state.filename !== entryFile) { - return - } - - const { polyfills } = state.opts - const { createImport } = require('@babel/preset-env/lib/utils') - - // Imports are injected in reverse order - polyfills.slice().reverse().forEach((p) => { - createImport(path, p) - }) - } - } - } -} diff --git a/packages/nuxt3/src/builder.ts b/packages/nuxt3/src/builder.ts index 13852c3c6d..88e2927d81 100644 --- a/packages/nuxt3/src/builder.ts +++ b/packages/nuxt3/src/builder.ts @@ -2,7 +2,7 @@ import { join, relative } from 'path' import fsExtra from 'fs-extra' import { debounce } from 'lodash' import { DeterminedGlobals, determineGlobals } from '@nuxt/kit' -import { Nuxt } from '../core' +import { Nuxt } from './nuxt' import { templateData, compileTemplates, @@ -11,7 +11,7 @@ import { } from './template' import { createWatcher } from './watch' import { createApp, NuxtApp } from './app' -import Ignore from './ignore' +import Ignore from './utils/ignore' export class Builder { nuxt: Nuxt diff --git a/packages/nuxt3/src/template.ts b/packages/nuxt3/src/template.ts index 78ddd6655f..c4a5a54339 100644 --- a/packages/nuxt3/src/template.ts +++ b/packages/nuxt3/src/template.ts @@ -2,7 +2,7 @@ import { join, relative, dirname } from 'path' import fsExtra from 'fs-extra' import globby from 'globby' import lodashTemplate from 'lodash/template' -import * as nxt from './nxt' +import * as nxt from './utils/nxt' export interface NuxtTemplate { src: string // Absolute path to source file diff --git a/packages/nuxt3/src/ignore.ts b/packages/nuxt3/src/utils/ignore.ts similarity index 100% rename from packages/nuxt3/src/ignore.ts rename to packages/nuxt3/src/utils/ignore.ts diff --git a/packages/nuxt3/src/utils.ts b/packages/nuxt3/src/utils/index.ts similarity index 91% rename from packages/nuxt3/src/utils.ts rename to packages/nuxt3/src/utils/index.ts index 6b42370045..d33fadf310 100644 --- a/packages/nuxt3/src/utils.ts +++ b/packages/nuxt3/src/utils/index.ts @@ -1,6 +1,6 @@ import { resolve } from 'path' import globby from 'globby' -import { Builder } from './builder' +import { Builder } from '../builder' // TODO: move to core resolver export async function resolveFiles (builder: Builder, pattern: string, srcDir: string) { diff --git a/packages/nuxt3/src/nxt.ts b/packages/nuxt3/src/utils/nxt.ts similarity index 96% rename from packages/nuxt3/src/nxt.ts rename to packages/nuxt3/src/utils/nxt.ts index 5ec4a2075f..a3566da332 100644 --- a/packages/nuxt3/src/nxt.ts +++ b/packages/nuxt3/src/utils/nxt.ts @@ -1,7 +1,7 @@ import { basename, extname } from 'path' import hash from 'hash-sum' import { camelCase } from 'scule' -import { NuxtRoute } from './pages' +import { NuxtRoute } from '../pages' // NXT is a set of utils for serializing JavaScript data to JS code export const serialize = data => JSON.stringify(data, null, 2).replace(/"{(.+)}"/g, '$1') diff --git a/packages/nuxt3/src/watch.ts b/packages/nuxt3/src/watch.ts index d148fec01a..c61db09d92 100644 --- a/packages/nuxt3/src/watch.ts +++ b/packages/nuxt3/src/watch.ts @@ -1,7 +1,7 @@ import chokidar, { WatchOptions } from 'chokidar' import defu from 'defu' import consola from 'consola' -import Ignore from './ignore' +import Ignore from './utils/ignore' export function createWatcher ( pattern: string, diff --git a/packages/nuxt3/src/babel-preset-app/index.js b/packages/nuxt3/src/webpack/utils/babel-preset.js similarity index 86% rename from packages/nuxt3/src/babel-preset-app/index.js rename to packages/nuxt3/src/webpack/utils/babel-preset.js index 858d1ef2e3..c6094d6b52 100644 --- a/packages/nuxt3/src/babel-preset-app/index.js +++ b/packages/nuxt3/src/webpack/utils/babel-preset.js @@ -122,7 +122,7 @@ module.exports = (api, options = {}) => { } ) ) - plugins.push([require('./polyfills-plugin'), { polyfills }]) + plugins.push([polyfillsPlugin, { polyfills }]) } // Pass options along to babel-preset-env @@ -175,3 +175,28 @@ module.exports = (api, options = {}) => { plugins } } + +// Add polyfill imports to the first file encountered. +function polyfillsPlugin ({ _types }) { + let entryFile + return { + name: 'inject-polyfills', + visitor: { + Program (path, state) { + if (!entryFile) { + entryFile = state.filename + } else if (state.filename !== entryFile) { + return + } + + const { polyfills } = state.opts + const { createImport } = require('@babel/preset-env/lib/utils') + + // Imports are injected in reverse order + polyfills.slice().reverse().forEach((p) => { + createImport(path, p) + }) + } + } + } +}