mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 13:48:13 +00:00
Merge branch '3.x' into feat/pages
This commit is contained in:
commit
e87d0613b3
@ -7,7 +7,6 @@ import type { Options as FileLoaderOptions } from 'file-loader'
|
|||||||
import type { Options as HtmlMinifierOptions } from 'html-minifier'
|
import type { Options as HtmlMinifierOptions } from 'html-minifier'
|
||||||
import type * as Less from 'less'
|
import type * as Less from 'less'
|
||||||
import type { Options as SassOptions } from 'node-sass'
|
import type { Options as SassOptions } from 'node-sass'
|
||||||
import type { Options as OptimizeCssAssetsWebpackPluginOptions } from 'optimize-css-assets-webpack-plugin'
|
|
||||||
import type { Plugin as PostcssPlugin } from 'postcss'
|
import type { Plugin as PostcssPlugin } from 'postcss'
|
||||||
import type { Options as PugOptions } from 'pug'
|
import type { Options as PugOptions } from 'pug'
|
||||||
import type { TerserPluginOptions } from 'terser-webpack-plugin'
|
import type { TerserPluginOptions } from 'terser-webpack-plugin'
|
||||||
@ -265,8 +264,11 @@ export default () => ({
|
|||||||
embed: 'src'
|
embed: 'src'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: {},
|
css: {
|
||||||
|
esModule: false
|
||||||
|
},
|
||||||
cssModules: {
|
cssModules: {
|
||||||
|
esModule: false,
|
||||||
modules: {
|
modules: {
|
||||||
localIdentName: '[local]_[hash:base64:5]'
|
localIdentName: '[local]_[hash:base64:5]'
|
||||||
}
|
}
|
||||||
@ -287,6 +289,7 @@ export default () => ({
|
|||||||
runtimeChunk: 'single',
|
runtimeChunk: 'single',
|
||||||
minimize: undefined as boolean | undefined,
|
minimize: undefined as boolean | undefined,
|
||||||
minimizer: undefined,
|
minimizer: undefined,
|
||||||
|
cssMinimizer: undefined,
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
chunks: 'all',
|
chunks: 'all',
|
||||||
name: undefined,
|
name: undefined,
|
||||||
@ -296,8 +299,7 @@ export default () => ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} as WebpackConfiguration['optimization'],
|
} as WebpackConfiguration['optimization'] & { cssMinimizer: undefined | boolean | Record<string, any> },
|
||||||
optimizeCSS: undefined as undefined | OptimizeCssAssetsWebpackPluginOptions | boolean,
|
|
||||||
/**
|
/**
|
||||||
* Enable [thread-loader](https://github.com/webpack-contrib/thread-loader#thread-loader) in webpack building
|
* Enable [thread-loader](https://github.com/webpack-contrib/thread-loader#thread-loader) in webpack building
|
||||||
*
|
*
|
||||||
|
@ -345,9 +345,9 @@ function normalizeConfig (_options: CliConfiguration) {
|
|||||||
options.build.optimization.minimize = !options.dev
|
options.build.optimization.minimize = !options.dev
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable optimizeCSS only when extractCSS is enabled
|
// Enable cssMinimizer only when extractCSS is enabled
|
||||||
if (options.build.optimizeCSS === undefined) {
|
if (options.build.optimization.cssMinimizer === undefined) {
|
||||||
options.build.optimizeCSS = options.build.extractCSS ? {} : false
|
options.build.optimization.cssMinimizer = options.build.extractCSS ? {} : false
|
||||||
}
|
}
|
||||||
|
|
||||||
const { loaders } = options.build
|
const { loaders } = options.build
|
||||||
|
@ -3,7 +3,7 @@ import querystring from 'querystring'
|
|||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import HTMLPlugin from 'html-webpack-plugin'
|
import HTMLPlugin from 'html-webpack-plugin'
|
||||||
import BundleAnalyzer from 'webpack-bundle-analyzer'
|
import BundleAnalyzer from 'webpack-bundle-analyzer'
|
||||||
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
|
||||||
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
||||||
|
|
||||||
import CorsPlugin from '../plugins/vue/cors'
|
import CorsPlugin from '../plugins/vue/cors'
|
||||||
@ -89,13 +89,10 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
|
|
||||||
minimizer () {
|
minimizer () {
|
||||||
const minimizer = super.minimizer()
|
const minimizer = super.minimizer()
|
||||||
const { optimizeCSS } = this.options.build
|
const { cssMinimizer } = this.options.build.optimization
|
||||||
|
|
||||||
// https://github.com/NMFR/optimize-css-assets-webpack-plugin
|
if (cssMinimizer) {
|
||||||
// https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production
|
minimizer.push(new CssMinimizerPlugin(Object.assign({}, cssMinimizer)))
|
||||||
// TODO: Remove OptimizeCSSAssetsPlugin when upgrading to webpack 5
|
|
||||||
if (optimizeCSS) {
|
|
||||||
minimizer.push(new OptimizeCSSAssetsPlugin(Object.assign({}, optimizeCSS)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return minimizer
|
return minimizer
|
||||||
|
@ -25,11 +25,6 @@ export default class StyleLoader {
|
|||||||
return this.options.build.extractCSS
|
return this.options.build.extractCSS
|
||||||
}
|
}
|
||||||
|
|
||||||
get onlyLocals () {
|
|
||||||
// Not supported anymore by css-loader
|
|
||||||
return false // Boolean(this.isServer && this.extractCSS)
|
|
||||||
}
|
|
||||||
|
|
||||||
normalize (loaders) {
|
normalize (loaders) {
|
||||||
loaders = wrapArray(loaders)
|
loaders = wrapArray(loaders)
|
||||||
return loaders.map(loader => (typeof loader === 'string' ? { loader } : loader))
|
return loaders.map(loader => (typeof loader === 'string' ? { loader } : loader))
|
||||||
@ -74,10 +69,11 @@ export default class StyleLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
css (options) {
|
css (options) {
|
||||||
options.onlyLocals = this.onlyLocals
|
|
||||||
const cssLoader = { loader: 'css-loader', options }
|
const cssLoader = { loader: 'css-loader', options }
|
||||||
|
|
||||||
if (options.onlyLocals) {
|
if (this.isServer && this.extractCSS) {
|
||||||
|
options.modules = options.modules || {}
|
||||||
|
options.modules.exportOnlyLocals = true
|
||||||
return [cssLoader]
|
return [cssLoader]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user