mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-04 11:52:39 +02:00
feat(v2): add ability to create unminimized bundles (#2474)
This commit is contained in:
parent
a869d5d705
commit
fa2e263ce8
7 changed files with 73 additions and 54 deletions
1
packages/docusaurus-types/src/index.d.ts
vendored
1
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -64,6 +64,7 @@ export interface StartCLIOptions {
|
||||||
export interface BuildCLIOptions {
|
export interface BuildCLIOptions {
|
||||||
bundleAnalyzer: boolean;
|
bundleAnalyzer: boolean;
|
||||||
outDir: string;
|
outDir: string;
|
||||||
|
minify: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoadContext {
|
export interface LoadContext {
|
||||||
|
|
|
@ -45,10 +45,15 @@ cli
|
||||||
'--out-dir <dir>',
|
'--out-dir <dir>',
|
||||||
'The full path for the new output directory, relative to the current workspace (default = build).',
|
'The full path for the new output directory, relative to the current workspace (default = build).',
|
||||||
)
|
)
|
||||||
.action((siteDir = '.', {bundleAnalyzer, outDir}) => {
|
.option(
|
||||||
|
'--no-minify',
|
||||||
|
'Build website without minimizing JS bundles (default = false)',
|
||||||
|
)
|
||||||
|
.action((siteDir = '.', {bundleAnalyzer, outDir, minify}) => {
|
||||||
wrapCommand(build)(path.resolve(siteDir), {
|
wrapCommand(build)(path.resolve(siteDir), {
|
||||||
bundleAnalyzer,
|
bundleAnalyzer,
|
||||||
outDir,
|
outDir,
|
||||||
|
minify,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,9 @@ export async function build(
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
'client-manifest.json',
|
'client-manifest.json',
|
||||||
);
|
);
|
||||||
let clientConfig: Configuration = merge(createClientConfig(props), {
|
let clientConfig: Configuration = merge(
|
||||||
|
createClientConfig(props, cliOptions.minify),
|
||||||
|
{
|
||||||
plugins: [
|
plugins: [
|
||||||
// Remove/clean build folders before building bundles.
|
// Remove/clean build folders before building bundles.
|
||||||
new CleanWebpackPlugin({verbose: false}),
|
new CleanWebpackPlugin({verbose: false}),
|
||||||
|
@ -72,7 +74,8 @@ export async function build(
|
||||||
filename: clientManifestPath,
|
filename: clientManifestPath,
|
||||||
}),
|
}),
|
||||||
].filter(Boolean) as Plugin[],
|
].filter(Boolean) as Plugin[],
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let serverConfig: Configuration = createServerConfig(props);
|
let serverConfig: Configuration = createServerConfig(props);
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,13 @@ export function excludeJS(modulePath: string) {
|
||||||
export function createBaseConfig(
|
export function createBaseConfig(
|
||||||
props: Props,
|
props: Props,
|
||||||
isServer: boolean,
|
isServer: boolean,
|
||||||
|
minify: boolean,
|
||||||
): Configuration {
|
): Configuration {
|
||||||
const {outDir, siteDir, baseUrl, generatedFilesDir, routesPaths} = props;
|
const {outDir, siteDir, baseUrl, generatedFilesDir, routesPaths} = props;
|
||||||
|
|
||||||
const totalPages = routesPaths.length;
|
const totalPages = routesPaths.length;
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode: isProd ? 'production' : 'development',
|
mode: isProd ? 'production' : 'development',
|
||||||
output: {
|
output: {
|
||||||
|
@ -78,8 +80,9 @@ export function createBaseConfig(
|
||||||
optimization: {
|
optimization: {
|
||||||
removeAvailableModules: false,
|
removeAvailableModules: false,
|
||||||
// Only minimize client bundle in production because server bundle is only used for static site generation
|
// Only minimize client bundle in production because server bundle is only used for static site generation
|
||||||
minimize: isProd && !isServer,
|
minimize: minify && isProd && !isServer,
|
||||||
minimizer: isProd
|
minimizer:
|
||||||
|
minify && isProd
|
||||||
? [
|
? [
|
||||||
new TerserPlugin({
|
new TerserPlugin({
|
||||||
cache: true,
|
cache: true,
|
||||||
|
|
|
@ -15,10 +15,13 @@ import {createBaseConfig} from './base';
|
||||||
import ChunkAssetPlugin from './plugins/ChunkAssetPlugin';
|
import ChunkAssetPlugin from './plugins/ChunkAssetPlugin';
|
||||||
import LogPlugin from './plugins/LogPlugin';
|
import LogPlugin from './plugins/LogPlugin';
|
||||||
|
|
||||||
export function createClientConfig(props: Props): Configuration {
|
export function createClientConfig(
|
||||||
|
props: Props,
|
||||||
|
minify: boolean = true,
|
||||||
|
): Configuration {
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
const isBuilding = process.argv[2] === 'build';
|
const isBuilding = process.argv[2] === 'build';
|
||||||
const config = createBaseConfig(props, false);
|
const config = createBaseConfig(props, false, minify);
|
||||||
|
|
||||||
const clientConfig = merge(config, {
|
const clientConfig = merge(config, {
|
||||||
entry: [
|
entry: [
|
||||||
|
|
|
@ -15,7 +15,10 @@ import {createBaseConfig} from './base';
|
||||||
import WaitPlugin from './plugins/WaitPlugin';
|
import WaitPlugin from './plugins/WaitPlugin';
|
||||||
import LogPlugin from './plugins/LogPlugin';
|
import LogPlugin from './plugins/LogPlugin';
|
||||||
|
|
||||||
export function createServerConfig(props: Props): Configuration {
|
export function createServerConfig(
|
||||||
|
props: Props,
|
||||||
|
minify: boolean = true,
|
||||||
|
): Configuration {
|
||||||
const {
|
const {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
routesPaths,
|
routesPaths,
|
||||||
|
@ -24,7 +27,7 @@ export function createServerConfig(props: Props): Configuration {
|
||||||
preBodyTags,
|
preBodyTags,
|
||||||
postBodyTags,
|
postBodyTags,
|
||||||
} = props;
|
} = props;
|
||||||
const config = createBaseConfig(props, true);
|
const config = createBaseConfig(props, true, minify);
|
||||||
|
|
||||||
const routesLocation = {};
|
const routesLocation = {};
|
||||||
// Array of paths to be rendered. Relative to output directory
|
// Array of paths to be rendered. Relative to output directory
|
||||||
|
|
|
@ -65,6 +65,7 @@ Compiles your site for production.
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `--bundle-analyzer` | | Analyze your bundle with [bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) |
|
| `--bundle-analyzer` | | Analyze your bundle with [bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) |
|
||||||
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
|
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
|
||||||
|
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
|
||||||
|
|
||||||
### `docusaurus swizzle`
|
### `docusaurus swizzle`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue