feat(v2): better splitchunks and babel default (#1653)

* feat(v2): better splitchunks and babel default

* common chunks

* chunks: all
This commit is contained in:
Endi 2019-07-14 00:38:48 +07:00 committed by Yangshun Tay
parent 9e9ad1f2b8
commit 22ce04d3fb
4 changed files with 23 additions and 19 deletions

View file

@ -10,10 +10,10 @@
"dependencies": {
"classnames": "^2.2.6",
"clipboard": "^2.0.4",
"prism-react-renderer": "^0.1.6",
"prism-react-renderer": "^0.1.7",
"react-live": "^2.1.2",
"react-loadable": "^5.5.0",
"react-loadable-visibility": "^2.5.1"
"react-loadable-visibility": "^3.0.1"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0",

View file

@ -18,6 +18,8 @@ import styles from './styles.module.css';
const Playground = LoadableVisibility({
loader: () => import('@theme/Playground'),
loading: Loading,
modules: ['@theme/Playground'],
webpack: () => [require.resolveWeak('@theme/Playground')],
});
export default ({children, className: languageClassName, live, ...props}) => {

View file

@ -28,8 +28,10 @@ export function createBaseConfig(
baseUrl,
generatedFilesDir,
cliOptions: {cacheLoader},
routesPaths,
} = props;
const totalPages = routesPaths.length;
const isProd = process.env.NODE_ENV === 'production';
return {
mode: isProd ? 'production' : 'development',
@ -89,6 +91,12 @@ export function createBaseConfig(
cacheGroups: {
// disable the built-in cacheGroups
default: false,
common: {
name: 'common',
chunks: 'all',
minChunks: totalPages > 2 ? totalPages * 0.5 : 2,
priority: 40,
},
vendor: {
test: /[\\/]node_modules[\\/]/,
priority: 30,
@ -110,13 +118,6 @@ export function createBaseConfig(
// create chunk regardless of the size of the chunk
enforce: true,
},
common: {
name: 'common',
minChunks: 2,
priority: 10,
reuseExistingChunk: true,
enforce: true,
},
},
},
},
@ -124,12 +125,8 @@ export function createBaseConfig(
rules: [
{
test: /\.jsx?$/,
exclude: modulePath => {
// Don't transpile node_modules except any docusaurus package
return (
/node_modules/.test(modulePath) && !/docusaurus/.test(modulePath)
);
},
include: [siteDir, /docusaurus/],
exclude: /node_modules/,
use: [
cacheLoader && getCacheLoader(isServer),
getBabelLoader(isServer),