Skip to content

Commit

Permalink
Allow @next plugins to be loaded without experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Nov 4, 2020
1 parent a1ea352 commit 959c1a1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 40 deletions.
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 @@ -21,7 +21,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 @@ -210,24 +210,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 @@ -248,7 +239,6 @@ export default async function getBaseWebpackConfig(
cwd: dir,
// Webpack 5 has a built-in loader cache
cache: !isWebpack5,
babelPresetPlugins,
hasModern: !!config.experimental.modern,
development: dev,
hasReactRefresh,
Expand All @@ -266,9 +256,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 @@ -969,9 +958,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 @@ -1193,7 +1180,6 @@ export default async function getBaseWebpackConfig(
trailingSlash: config.trailingSlash,
modern: config.experimental.modern,
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 @@ -58,7 +58,6 @@ module.exports = babelLoader.custom((babel) => {
isModern: opts.isModern,
pagesDir: opts.pagesDir,
hasModern: opts.hasModern,
babelPresetPlugins: opts.babelPresetPlugins,
development: opts.development,
hasReactRefresh: opts.hasReactRefresh,
hasJsxRuntime: opts.hasJsxRuntime,
Expand Down Expand Up @@ -98,7 +97,6 @@ module.exports = babelLoader.custom((babel) => {
delete loader.isModern
delete loader.hasModern
delete loader.pagesDir
delete loader.babelPresetPlugins
delete loader.development
delete loader.hasReactRefresh
delete loader.hasJsxRuntime
Expand All @@ -113,7 +111,6 @@ module.exports = babelLoader.custom((babel) => {
isModern,
hasModern,
pagesDir,
babelPresetPlugins,
development,
hasReactRefresh,
hasJsxRuntime,
Expand Down Expand Up @@ -255,13 +252,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 @@ -52,7 +52,6 @@ const defaultConfig: { [key: string]: any } = {
(os.cpus() || { length: 1 }).length) - 1
),
modern: false,
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 @@ -233,7 +233,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.

0 comments on commit 959c1a1

Please sign in to comment.