Unverified Commit 5d8968f6 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove launched experimental options (#12197)

parent fcc6d7d4
module.exports = {
experimental: {
scss: true,
},
}
...@@ -448,9 +448,11 @@ export default async function getBaseWebpackConfig( ...@@ -448,9 +448,11 @@ export default async function getBaseWebpackConfig(
? 'anonymous' ? 'anonymous'
: config.crossOrigin : config.crossOrigin
let customAppFile: string | null = config.experimental.css let customAppFile: string | null = await findPageFile(
? await findPageFile(pagesDir, '/_app', config.pageExtensions) pagesDir,
: null '/_app',
config.pageExtensions
)
if (customAppFile) { if (customAppFile) {
customAppFile = path.resolve(path.join(pagesDir, customAppFile)) customAppFile = path.resolve(path.join(pagesDir, customAppFile))
} }
...@@ -644,20 +646,19 @@ export default async function getBaseWebpackConfig( ...@@ -644,20 +646,19 @@ export default async function getBaseWebpackConfig(
terserOptions, terserOptions,
}), }),
// Minify CSS // Minify CSS
config.experimental.css && new CssMinimizerPlugin({
new CssMinimizerPlugin({ postcssOptions: {
postcssOptions: { map: {
map: { // `inline: false` generates the source map in a separate file.
// `inline: false` generates the source map in a separate file. // Otherwise, the CSS file is needlessly large.
// Otherwise, the CSS file is needlessly large. inline: false,
inline: false, // `annotation: false` skips appending the `sourceMappingURL`
// `annotation: false` skips appending the `sourceMappingURL` // to the end of the CSS file. Webpack already handles this.
// to the end of the CSS file. Webpack already handles this. annotation: false,
annotation: false,
},
}, },
}), },
].filter(Boolean), }),
],
}, },
context: dir, context: dir,
node: { node: {
...@@ -1031,8 +1032,6 @@ export default async function getBaseWebpackConfig( ...@@ -1031,8 +1032,6 @@ export default async function getBaseWebpackConfig(
customAppFile, customAppFile,
isDevelopment: dev, isDevelopment: dev,
isServer, isServer,
hasSupportCss: !!config.experimental.css,
hasSupportScss: !!config.experimental.scss,
assetPrefix: config.assetPrefix || '', assetPrefix: config.assetPrefix || '',
sassOptions: config.experimental.sassOptions, sassOptions: config.experimental.sassOptions,
}) })
...@@ -1095,49 +1094,47 @@ export default async function getBaseWebpackConfig( ...@@ -1095,49 +1094,47 @@ export default async function getBaseWebpackConfig(
return false return false
} }
if (config.experimental.css) { const hasUserCssConfig =
const hasUserCssConfig = webpackConfig.module?.rules.some(
webpackConfig.module?.rules.some( rule => canMatchCss(rule.test) || canMatchCss(rule.include)
rule => canMatchCss(rule.test) || canMatchCss(rule.include) ) ?? false
) ?? false
if (hasUserCssConfig) {
// only show warning for one build
if (isServer) {
console.warn(
chalk.yellow.bold('Warning: ') +
chalk.bold(
'Built-in CSS support is being disabled due to custom CSS configuration being detected.\n'
) +
'See here for more info: https://err.sh/next.js/built-in-css-disabled\n'
)
}
if (webpackConfig.module?.rules.length) { if (hasUserCssConfig) {
// Remove default CSS Loader // only show warning for one build
webpackConfig.module.rules = webpackConfig.module.rules.filter( if (isServer) {
r => console.warn(
!( chalk.yellow.bold('Warning: ') +
typeof r.oneOf?.[0]?.options === 'object' && chalk.bold(
r.oneOf[0].options.__next_css_remove === true 'Built-in CSS support is being disabled due to custom CSS configuration being detected.\n'
) ) +
) 'See here for more info: https://err.sh/next.js/built-in-css-disabled\n'
} )
if (webpackConfig.plugins?.length) { }
// Disable CSS Extraction Plugin
webpackConfig.plugins = webpackConfig.plugins.filter( if (webpackConfig.module?.rules.length) {
p => (p as any).__next_css_remove !== true // Remove default CSS Loader
) webpackConfig.module.rules = webpackConfig.module.rules.filter(
} r =>
if (webpackConfig.optimization?.minimizer?.length) { !(
// Disable CSS Minifier typeof r.oneOf?.[0]?.options === 'object' &&
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.filter( r.oneOf[0].options.__next_css_remove === true
e => (e as any).__next_css_remove !== true )
) )
}
} else {
await __overrideCssConfiguration(dir, !dev, webpackConfig)
} }
if (webpackConfig.plugins?.length) {
// Disable CSS Extraction Plugin
webpackConfig.plugins = webpackConfig.plugins.filter(
p => (p as any).__next_css_remove !== true
)
}
if (webpackConfig.optimization?.minimizer?.length) {
// Disable CSS Minifier
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.filter(
e => (e as any).__next_css_remove !== true
)
}
} else {
await __overrideCssConfiguration(dir, !dev, webpackConfig)
} }
// check if using @zeit/next-typescript and show warning // check if using @zeit/next-typescript and show warning
......
...@@ -25,15 +25,9 @@ const regexSassGlobal = /(?<!\.module)\.(scss|sass)$/ ...@@ -25,15 +25,9 @@ const regexSassGlobal = /(?<!\.module)\.(scss|sass)$/
const regexSassModules = /\.module\.(scss|sass)$/ const regexSassModules = /\.module\.(scss|sass)$/
export const css = curry(async function css( export const css = curry(async function css(
enabled: boolean,
scssEnabled: boolean,
ctx: ConfigurationContext, ctx: ConfigurationContext,
config: Configuration config: Configuration
) { ) {
if (!enabled) {
return config
}
const sassPreprocessors: webpack.RuleSetUseItem[] = [ const sassPreprocessors: webpack.RuleSetUseItem[] = [
// First, process files with `sass-loader`: this inlines content, and // First, process files with `sass-loader`: this inlines content, and
// compiles away the proprietary syntax. // compiles away the proprietary syntax.
...@@ -128,41 +122,36 @@ export const css = curry(async function css( ...@@ -128,41 +122,36 @@ export const css = curry(async function css(
], ],
}) })
) )
if (scssEnabled) { fns.push(
fns.push( loader({
loader({ oneOf: [
oneOf: [ // Opt-in support for Sass (using .scss or .sass extensions).
// Opt-in support for Sass (using .scss or .sass extensions). {
{ // Sass Modules should never have side effects. This setting will
// Sass Modules should never have side effects. This setting will // allow unused Sass to be removed from the production build.
// allow unused Sass to be removed from the production build. // We ensure this by disallowing `:global()` Sass at the top-level
// We ensure this by disallowing `:global()` Sass at the top-level // via the `pure` mode in `css-loader`.
// via the `pure` mode in `css-loader`. sideEffects: false,
sideEffects: false, // Sass Modules are activated via this specific extension.
// Sass Modules are activated via this specific extension. test: regexSassModules,
test: regexSassModules, // Sass Modules are only supported in the user's application. We're
// Sass Modules are only supported in the user's application. We're // not yet allowing Sass imports _within_ `node_modules`.
// not yet allowing Sass imports _within_ `node_modules`. issuer: {
issuer: { include: [ctx.rootDirectory],
include: [ctx.rootDirectory], exclude: /node_modules/,
exclude: /node_modules/,
},
use: getCssModuleLoader(ctx, postCssPlugins, sassPreprocessors),
}, },
], use: getCssModuleLoader(ctx, postCssPlugins, sassPreprocessors),
}) },
) ],
} })
)
// Throw an error for CSS Modules used outside their supported scope // Throw an error for CSS Modules used outside their supported scope
fns.push( fns.push(
loader({ loader({
oneOf: [ oneOf: [
{ {
test: [ test: [regexCssModules, regexSassModules].filter(Boolean),
regexCssModules,
(scssEnabled && regexSassModules) as RegExp,
].filter(Boolean),
use: { use: {
loader: 'error-loader', loader: 'error-loader',
options: { options: {
...@@ -179,10 +168,7 @@ export const css = curry(async function css( ...@@ -179,10 +168,7 @@ export const css = curry(async function css(
loader({ loader({
oneOf: [ oneOf: [
{ {
test: [ test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
use: require.resolve('next/dist/compiled/ignore-loader'), use: require.resolve('next/dist/compiled/ignore-loader'),
}, },
], ],
...@@ -205,24 +191,22 @@ export const css = curry(async function css( ...@@ -205,24 +191,22 @@ export const css = curry(async function css(
], ],
}) })
) )
if (scssEnabled) { fns.push(
fns.push( loader({
loader({ oneOf: [
oneOf: [ {
{ // A global Sass import always has side effects. Webpack will tree
// A global Sass import always has side effects. Webpack will tree // shake the Sass without this option if the issuer claims to have
// shake the Sass without this option if the issuer claims to have // no side-effects.
// no side-effects. // See https://github.com/webpack/webpack/issues/6571
// See https://github.com/webpack/webpack/issues/6571 sideEffects: true,
sideEffects: true, test: regexSassGlobal,
test: regexSassGlobal, issuer: { include: ctx.customAppFile },
issuer: { include: ctx.customAppFile }, use: getGlobalCssLoader(ctx, postCssPlugins, sassPreprocessors),
use: getGlobalCssLoader(ctx, postCssPlugins, sassPreprocessors), },
}, ],
], })
}) )
)
}
} }
// Throw an error for Global CSS used inside of `node_modules` // Throw an error for Global CSS used inside of `node_modules`
...@@ -230,10 +214,7 @@ export const css = curry(async function css( ...@@ -230,10 +214,7 @@ export const css = curry(async function css(
loader({ loader({
oneOf: [ oneOf: [
{ {
test: [ test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
issuer: { include: [/node_modules/] }, issuer: { include: [/node_modules/] },
use: { use: {
loader: 'error-loader', loader: 'error-loader',
...@@ -251,10 +232,7 @@ export const css = curry(async function css( ...@@ -251,10 +232,7 @@ export const css = curry(async function css(
loader({ loader({
oneOf: [ oneOf: [
{ {
test: [ test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
use: { use: {
loader: 'error-loader', loader: 'error-loader',
options: { options: {
......
...@@ -10,8 +10,6 @@ export async function build( ...@@ -10,8 +10,6 @@ export async function build(
customAppFile, customAppFile,
isDevelopment, isDevelopment,
isServer, isServer,
hasSupportCss,
hasSupportScss,
assetPrefix, assetPrefix,
sassOptions, sassOptions,
}: { }: {
...@@ -19,8 +17,6 @@ export async function build( ...@@ -19,8 +17,6 @@ export async function build(
customAppFile: string | null customAppFile: string | null
isDevelopment: boolean isDevelopment: boolean
isServer: boolean isServer: boolean
hasSupportCss: boolean
hasSupportScss: boolean
assetPrefix: string assetPrefix: string
sassOptions: any sassOptions: any
} }
...@@ -40,6 +36,6 @@ export async function build( ...@@ -40,6 +36,6 @@ export async function build(
sassOptions, sassOptions,
} }
const fn = pipe(base(ctx), css(hasSupportCss, hasSupportScss, ctx)) const fn = pipe(base(ctx), css(ctx))
return fn(config) return fn(config)
} }
...@@ -158,7 +158,6 @@ export type DocumentProps = DocumentInitialProps & { ...@@ -158,7 +158,6 @@ export type DocumentProps = DocumentInitialProps & {
hybridAmp: boolean hybridAmp: boolean
staticMarkup: boolean staticMarkup: boolean
isDevelopment: boolean isDevelopment: boolean
hasCssMode: boolean
devFiles: string[] devFiles: string[]
files: string[] files: string[]
lowPriorityFiles: string[] lowPriorityFiles: string[]
......
...@@ -41,8 +41,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -41,8 +41,6 @@ const defaultConfig: { [key: string]: any } = {
(Number(process.env.CIRCLE_NODE_TOTAL) || (Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1 (os.cpus() || { length: 1 }).length) - 1
), ),
css: true,
scss: true,
documentMiddleware: false, documentMiddleware: false,
granularChunks: true, granularChunks: true,
modern: false, modern: false,
...@@ -155,15 +153,6 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -155,15 +153,6 @@ function assignDefaults(userConfig: { [key: string]: any }) {
) )
} }
if (result.experimental) { if (result.experimental) {
if (result.experimental.css) {
// The new CSS support requires granular chunks be enabled.
if (result.experimental.granularChunks !== true) {
throw new Error(
`The new CSS support requires granular chunks be enabled.`
)
}
}
if (typeof result.experimental.basePath !== 'string') { if (typeof result.experimental.basePath !== 'string') {
throw new Error( throw new Error(
`Specified basePath is not a string, found type "${typeof result `Specified basePath is not a string, found type "${typeof result
......
...@@ -119,7 +119,6 @@ export default class Server { ...@@ -119,7 +119,6 @@ export default class Server {
assetPrefix?: string assetPrefix?: string
canonicalBase: string canonicalBase: string
documentMiddlewareEnabled: boolean documentMiddlewareEnabled: boolean
hasCssMode: boolean
dev?: boolean dev?: boolean
previewProps: __ApiPreviewProps previewProps: __ApiPreviewProps
customServer?: boolean customServer?: boolean
...@@ -174,7 +173,6 @@ export default class Server { ...@@ -174,7 +173,6 @@ export default class Server {
canonicalBase: this.nextConfig.amp.canonicalBase, canonicalBase: this.nextConfig.amp.canonicalBase,
documentMiddlewareEnabled: this.nextConfig.experimental documentMiddlewareEnabled: this.nextConfig.experimental
.documentMiddleware, .documentMiddleware,
hasCssMode: this.nextConfig.experimental.css,
staticMarkup, staticMarkup,
buildId: this.buildId, buildId: this.buildId,
generateEtags, generateEtags,
......
...@@ -141,7 +141,6 @@ export type RenderOptsPartial = { ...@@ -141,7 +141,6 @@ export type RenderOptsPartial = {
canonicalBase: string canonicalBase: string
runtimeConfig?: { [key: string]: any } runtimeConfig?: { [key: string]: any }
assetPrefix?: string assetPrefix?: string
hasCssMode: boolean
err?: Error | null err?: Error | null
autoExport?: boolean autoExport?: boolean
nextExport?: boolean nextExport?: boolean
...@@ -180,7 +179,6 @@ function renderDocument( ...@@ -180,7 +179,6 @@ function renderDocument(
isFallback, isFallback,
dynamicImportsIds, dynamicImportsIds,
dangerousAsPath, dangerousAsPath,
hasCssMode,
err, err,
dev, dev,
ampPath, ampPath,
...@@ -258,7 +256,6 @@ function renderDocument( ...@@ -258,7 +256,6 @@ function renderDocument(
ampPath, ampPath,
inAmpMode, inAmpMode,
isDevelopment: !!dev, isDevelopment: !!dev,
hasCssMode,
hybridAmp, hybridAmp,
staticMarkup, staticMarkup,
devFiles, devFiles,
......
...@@ -407,28 +407,27 @@ export class Head extends Component< ...@@ -407,28 +407,27 @@ export class Head extends Component<
return ( return (
<head {...this.props}> <head {...this.props}>
{this.context._documentProps.isDevelopment && {this.context._documentProps.isDevelopment && (
this.context._documentProps.hasCssMode && ( <>
<> <style
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
dangerouslySetInnerHTML={{
__html: `body{display:none}`,
}}
/>
<noscript
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
>
<style <style
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: `body{display:none}`, __html: `body{display:block}`,
}} }}
/> />
<noscript </noscript>
data-next-hide-fouc </>
data-ampdevmode={inAmpMode ? 'true' : undefined} )}
>
<style
dangerouslySetInnerHTML={{
__html: `body{display:block}`,
}}
/>
</noscript>
</>
)}
{children} {children}
{head} {head}
<meta <meta
...@@ -526,13 +525,12 @@ export class Head extends Component< ...@@ -526,13 +525,12 @@ export class Head extends Component<
)} )}
{!disableRuntimeJS && this.getPreloadDynamicChunks()} {!disableRuntimeJS && this.getPreloadDynamicChunks()}
{!disableRuntimeJS && this.getPreloadMainLinks()} {!disableRuntimeJS && this.getPreloadMainLinks()}
{this.context._documentProps.isDevelopment && {this.context._documentProps.isDevelopment && (
this.context._documentProps.hasCssMode && ( // this element is used to mount development styles so the
// this element is used to mount development styles so the // ordering matches production
// ordering matches production // (by default, style-loader injects at the bottom of <head />)
// (by default, style-loader injects at the bottom of <head />) <noscript id="__next_css__DO_NOT_USE__" />
<noscript id="__next_css__DO_NOT_USE__" /> )}
)}
{styles || null} {styles || null}
</> </>
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment