Skip to content

Commit

Permalink
Remove launched experimental options (#12197)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Apr 25, 2020
1 parent fcc6d7d commit 5d8968f
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 175 deletions.
5 changes: 0 additions & 5 deletions examples/with-carbon-components/next.config.js

This file was deleted.

115 changes: 56 additions & 59 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,11 @@ export default async function getBaseWebpackConfig(
? 'anonymous'
: config.crossOrigin

let customAppFile: string | null = config.experimental.css
? await findPageFile(pagesDir, '/_app', config.pageExtensions)
: null
let customAppFile: string | null = await findPageFile(
pagesDir,
'/_app',
config.pageExtensions
)
if (customAppFile) {
customAppFile = path.resolve(path.join(pagesDir, customAppFile))
}
Expand Down Expand Up @@ -644,20 +646,19 @@ export default async function getBaseWebpackConfig(
terserOptions,
}),
// Minify CSS
config.experimental.css &&
new CssMinimizerPlugin({
postcssOptions: {
map: {
// `inline: false` generates the source map in a separate file.
// Otherwise, the CSS file is needlessly large.
inline: false,
// `annotation: false` skips appending the `sourceMappingURL`
// to the end of the CSS file. Webpack already handles this.
annotation: false,
},
new CssMinimizerPlugin({
postcssOptions: {
map: {
// `inline: false` generates the source map in a separate file.
// Otherwise, the CSS file is needlessly large.
inline: false,
// `annotation: false` skips appending the `sourceMappingURL`
// to the end of the CSS file. Webpack already handles this.
annotation: false,
},
}),
].filter(Boolean),
},
}),
],
},
context: dir,
node: {
Expand Down Expand Up @@ -1031,8 +1032,6 @@ export default async function getBaseWebpackConfig(
customAppFile,
isDevelopment: dev,
isServer,
hasSupportCss: !!config.experimental.css,
hasSupportScss: !!config.experimental.scss,
assetPrefix: config.assetPrefix || '',
sassOptions: config.experimental.sassOptions,
})
Expand Down Expand Up @@ -1095,49 +1094,47 @@ export default async function getBaseWebpackConfig(
return false
}

if (config.experimental.css) {
const hasUserCssConfig =
webpackConfig.module?.rules.some(
rule => canMatchCss(rule.test) || canMatchCss(rule.include)
) ?? 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'
)
}
const hasUserCssConfig =
webpackConfig.module?.rules.some(
rule => canMatchCss(rule.test) || canMatchCss(rule.include)
) ?? false

if (webpackConfig.module?.rules.length) {
// Remove default CSS Loader
webpackConfig.module.rules = webpackConfig.module.rules.filter(
r =>
!(
typeof r.oneOf?.[0]?.options === 'object' &&
r.oneOf[0].options.__next_css_remove === true
)
)
}
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)
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) {
// Remove default CSS Loader
webpackConfig.module.rules = webpackConfig.module.rules.filter(
r =>
!(
typeof r.oneOf?.[0]?.options === 'object' &&
r.oneOf[0].options.__next_css_remove === true
)
)
}
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
Expand Down
106 changes: 42 additions & 64 deletions packages/next/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ const regexSassGlobal = /(?<!\.module)\.(scss|sass)$/
const regexSassModules = /\.module\.(scss|sass)$/

export const css = curry(async function css(
enabled: boolean,
scssEnabled: boolean,
ctx: ConfigurationContext,
config: Configuration
) {
if (!enabled) {
return config
}

const sassPreprocessors: webpack.RuleSetUseItem[] = [
// First, process files with `sass-loader`: this inlines content, and
// compiles away the proprietary syntax.
Expand Down Expand Up @@ -128,41 +122,36 @@ export const css = curry(async function css(
],
})
)
if (scssEnabled) {
fns.push(
loader({
oneOf: [
// Opt-in support for Sass (using .scss or .sass extensions).
{
// Sass Modules should never have side effects. This setting will
// allow unused Sass to be removed from the production build.
// We ensure this by disallowing `:global()` Sass at the top-level
// via the `pure` mode in `css-loader`.
sideEffects: false,
// Sass Modules are activated via this specific extension.
test: regexSassModules,
// Sass Modules are only supported in the user's application. We're
// not yet allowing Sass imports _within_ `node_modules`.
issuer: {
include: [ctx.rootDirectory],
exclude: /node_modules/,
},
use: getCssModuleLoader(ctx, postCssPlugins, sassPreprocessors),
fns.push(
loader({
oneOf: [
// Opt-in support for Sass (using .scss or .sass extensions).
{
// Sass Modules should never have side effects. This setting will
// allow unused Sass to be removed from the production build.
// We ensure this by disallowing `:global()` Sass at the top-level
// via the `pure` mode in `css-loader`.
sideEffects: false,
// Sass Modules are activated via this specific extension.
test: regexSassModules,
// Sass Modules are only supported in the user's application. We're
// not yet allowing Sass imports _within_ `node_modules`.
issuer: {
include: [ctx.rootDirectory],
exclude: /node_modules/,
},
],
})
)
}
use: getCssModuleLoader(ctx, postCssPlugins, sassPreprocessors),
},
],
})
)

// Throw an error for CSS Modules used outside their supported scope
fns.push(
loader({
oneOf: [
{
test: [
regexCssModules,
(scssEnabled && regexSassModules) as RegExp,
].filter(Boolean),
test: [regexCssModules, regexSassModules].filter(Boolean),
use: {
loader: 'error-loader',
options: {
Expand All @@ -179,10 +168,7 @@ export const css = curry(async function css(
loader({
oneOf: [
{
test: [
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
use: require.resolve('next/dist/compiled/ignore-loader'),
},
],
Expand All @@ -205,35 +191,30 @@ export const css = curry(async function css(
],
})
)
if (scssEnabled) {
fns.push(
loader({
oneOf: [
{
// A global Sass import always has side effects. Webpack will tree
// shake the Sass without this option if the issuer claims to have
// no side-effects.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
test: regexSassGlobal,
issuer: { include: ctx.customAppFile },
use: getGlobalCssLoader(ctx, postCssPlugins, sassPreprocessors),
},
],
})
)
}
fns.push(
loader({
oneOf: [
{
// A global Sass import always has side effects. Webpack will tree
// shake the Sass without this option if the issuer claims to have
// no side-effects.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
test: regexSassGlobal,
issuer: { include: ctx.customAppFile },
use: getGlobalCssLoader(ctx, postCssPlugins, sassPreprocessors),
},
],
})
)
}

// Throw an error for Global CSS used inside of `node_modules`
fns.push(
loader({
oneOf: [
{
test: [
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
issuer: { include: [/node_modules/] },
use: {
loader: 'error-loader',
Expand All @@ -251,10 +232,7 @@ export const css = curry(async function css(
loader({
oneOf: [
{
test: [
regexCssGlobal,
(scssEnabled && regexSassGlobal) as RegExp,
].filter(Boolean),
test: [regexCssGlobal, regexSassGlobal].filter(Boolean),
use: {
loader: 'error-loader',
options: {
Expand Down
6 changes: 1 addition & 5 deletions packages/next/build/webpack/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ export async function build(
customAppFile,
isDevelopment,
isServer,
hasSupportCss,
hasSupportScss,
assetPrefix,
sassOptions,
}: {
rootDirectory: string
customAppFile: string | null
isDevelopment: boolean
isServer: boolean
hasSupportCss: boolean
hasSupportScss: boolean
assetPrefix: string
sassOptions: any
}
Expand All @@ -40,6 +36,6 @@ export async function build(
sassOptions,
}

const fn = pipe(base(ctx), css(hasSupportCss, hasSupportScss, ctx))
const fn = pipe(base(ctx), css(ctx))
return fn(config)
}
1 change: 0 additions & 1 deletion packages/next/next-server/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export type DocumentProps = DocumentInitialProps & {
hybridAmp: boolean
staticMarkup: boolean
isDevelopment: boolean
hasCssMode: boolean
devFiles: string[]
files: string[]
lowPriorityFiles: string[]
Expand Down
11 changes: 0 additions & 11 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const defaultConfig: { [key: string]: any } = {
(Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1
),
css: true,
scss: true,
documentMiddleware: false,
granularChunks: true,
modern: false,
Expand Down Expand Up @@ -155,15 +153,6 @@ function assignDefaults(userConfig: { [key: string]: any }) {
)
}
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') {
throw new Error(
`Specified basePath is not a string, found type "${typeof result
Expand Down
2 changes: 0 additions & 2 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export default class Server {
assetPrefix?: string
canonicalBase: string
documentMiddlewareEnabled: boolean
hasCssMode: boolean
dev?: boolean
previewProps: __ApiPreviewProps
customServer?: boolean
Expand Down Expand Up @@ -174,7 +173,6 @@ export default class Server {
canonicalBase: this.nextConfig.amp.canonicalBase,
documentMiddlewareEnabled: this.nextConfig.experimental
.documentMiddleware,
hasCssMode: this.nextConfig.experimental.css,
staticMarkup,
buildId: this.buildId,
generateEtags,
Expand Down

0 comments on commit 5d8968f

Please sign in to comment.