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

Allow @next plugins to be loaded without experimental flag #18788

Closed
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
1 change: 0 additions & 1 deletion packages/next/build/plugins/collect-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const VALID_MIDDLEWARE = [
'on-init-server',
'on-error-client',
'on-error-server',
'babel-preset-build',
]

type ENV_OPTIONS = { [name: string]: string }
Expand Down
32 changes: 9 additions & 23 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,15 @@ export default async function getBaseWebpackConfig(
): Promise<webpack.Configuration> {
const productionBrowserSourceMaps =
config.experimental.productionBrowserSourceMaps && !isServer
let plugins: PluginMetaData[] = []
let babelPresetPlugins: { dir: string; config: any }[] = []
let plugins: PluginMetaData[] = await collectPlugins(
dir,
config.env,
config.plugins
)

const hasRewrites = rewrites.length > 0 || dev

if (config.experimental.plugins) {
plugins = await collectPlugins(dir, config.env, config.plugins)
pluginLoaderOptions.plugins = plugins

for (const plugin of plugins) {
if (plugin.middleware.includes('babel-preset-build')) {
babelPresetPlugins.push({
dir: plugin.directory,
config: plugin.config,
})
}
}
}
pluginLoaderOptions.plugins = plugins

const reactVersion = await getPackageVersion({ cwd: dir, name: 'react' })
const hasReactRefresh: boolean = dev && !isServer
Expand All @@ -242,7 +233,6 @@ export default async function getBaseWebpackConfig(
cwd: dir,
// Webpack 5 has a built-in loader cache
cache: !isWebpack5,
babelPresetPlugins,
development: dev,
hasReactRefresh,
hasJsxRuntime,
Expand All @@ -259,9 +249,8 @@ export default async function getBaseWebpackConfig(
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/,
...(config.experimental.plugins
? VALID_MIDDLEWARE.map((name) => new RegExp(`src(\\\\|/)${name}`))
: []),
// Compile plugins through babel
...VALID_MIDDLEWARE.map((name) => new RegExp(`src(\\\\|/)${name}`)),
]

// Support for NODE_PATH
Expand Down Expand Up @@ -954,9 +943,7 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_BUILD_INDICATOR': JSON.stringify(
config.devIndicators.buildActivity
),
'process.env.__NEXT_PLUGINS': JSON.stringify(
config.experimental.plugins
),
'process.env.__NEXT_PLUGINS': JSON.stringify(true),
'process.env.__NEXT_STRICT_MODE': JSON.stringify(
config.reactStrictMode
),
Expand Down Expand Up @@ -1153,7 +1140,6 @@ export default async function getBaseWebpackConfig(
pageExtensions: config.pageExtensions,
trailingSlash: config.trailingSlash,
buildActivity: config.devIndicators.buildActivity,
plugins: config.experimental.plugins,
reactStrictMode: config.reactStrictMode,
reactMode: config.experimental.reactMode,
optimizeFonts: config.experimental.optimizeFonts,
Expand Down
10 changes: 0 additions & 10 deletions packages/next/build/webpack/loaders/next-babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = babelLoader.custom((babel) => {
const custom = {
isServer: opts.isServer,
pagesDir: opts.pagesDir,
babelPresetPlugins: opts.babelPresetPlugins,
development: opts.development,
hasReactRefresh: opts.hasReactRefresh,
hasJsxRuntime: opts.hasJsxRuntime,
Expand Down Expand Up @@ -64,7 +63,6 @@ module.exports = babelLoader.custom((babel) => {
delete loader.cache
delete loader.distDir
delete loader.pagesDir
delete loader.babelPresetPlugins
delete loader.development
delete loader.hasReactRefresh
delete loader.hasJsxRuntime
Expand All @@ -77,7 +75,6 @@ module.exports = babelLoader.custom((babel) => {
customOptions: {
isServer,
pagesDir,
babelPresetPlugins,
development,
hasReactRefresh,
hasJsxRuntime,
Expand Down Expand Up @@ -199,13 +196,6 @@ module.exports = babelLoader.custom((babel) => {
},
]

for (const plugin of babelPresetPlugins) {
require(join(plugin.dir, 'src', 'babel-preset-build.js'))(
options,
plugin.config || {}
)
}

return options
},
}
Expand Down
1 change: 0 additions & 1 deletion packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const defaultConfig: { [key: string]: any } = {
(Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1
),
plugins: false,
profiling: false,
sprFlushToDisk: true,
reactMode: 'legacy',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class Server {

// call init-server middleware, this is also handled
// individually in serverless bundles when deployed
if (!dev && this.nextConfig.experimental.plugins) {
if (!dev) {
const initServer = require(join(this.serverBuildDir, 'init-server.js'))
.default
this.onErrorMiddleware = require(join(
Expand Down

This file was deleted.

9 changes: 3 additions & 6 deletions test/integration/next-plugins/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Next.js plugins', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = { env: { GA_TRACKING_ID: 'my-tracking-id' }, experimental: { plugins: true } }`
`module.exports = { env: { GA_TRACKING_ID: 'my-tracking-id' } }`
)
appPort = await findPort()
app = await launchApp(appDir, appPort, {
Expand All @@ -128,9 +128,6 @@ describe('Next.js plugins', () => {
nextConfigPath,
`
module.exports = {
experimental: {
plugins: true
},
plugins: [
{
name: '@next/plugin-google-analytics',
Expand Down Expand Up @@ -171,7 +168,7 @@ describe('Next.js plugins', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = { env: { GA_TRACKING_ID: 'my-tracking-id' }, experimental: { plugins: true } }`
`module.exports = { env: { GA_TRACKING_ID: 'my-tracking-id' } }`
)
const results = await nextBuild(appDir, undefined, {
stdout: true,
Expand All @@ -194,7 +191,7 @@ describe('Next.js plugins', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = { target: 'serverless', env: { GA_TRACKING_ID: 'my-tracking-id' }, experimental: { plugins: true } }`
`module.exports = { target: 'serverless', env: { GA_TRACKING_ID: 'my-tracking-id' } }`
)
const results = await nextBuild(appDir, undefined, {
stdout: true,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/size-limit/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ describe('Production response size', () => {
const delta = responseSizesBytes / 1024

// Expected difference: < 0.5
expect(delta).toBeCloseTo(281.4, 0)
expect(delta).toBeCloseTo(282.4, 0)
})
})