Skip to content

Commit

Permalink
chore(deps): update dependency kkt to v7.
Browse files Browse the repository at this point in the history
Upgrade react-scripts to v5, Support Webpack 5.x
kktjs/kkt#198
  • Loading branch information
jaywcjlove committed Jan 10, 2022
1 parent 1ca63a0 commit c86f7cb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 121 deletions.
150 changes: 39 additions & 111 deletions .kktrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import rawModules from '@kkt/raw-modules';
import scopePluginOptions from '@kkt/scope-plugin-options';
import pkg from './package.json';

export default (conf: Configuration, env: string, options: LoaderConfOptions) => {
export default (conf: Configuration, env: 'production' | 'development', options: LoaderConfOptions) => {
conf = lessModules(conf, env, options);
conf = rawModules(conf, env, { ...options });
conf = scopePluginOptions(conf, env, {
Expand All @@ -19,118 +19,46 @@ export default (conf: Configuration, env: string, options: LoaderConfOptions) =>
conf.plugins!.push(new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
}));
conf.optimization = {
...conf.optimization,
splitChunks: {
chunks: 'all', // async对异步引入的代码分割 initial 对同步引入代码分割 all对同步异步引入的分割都开启
minSize: 30000, // 字节 引入的文件大于30kb才进行分割
maxSize: 0, // 文件的最大尺寸,优先级:maxInitialRequest/maxAsyncRequests < maxSize < minSize,需要注意的是这个如果配置了,umi.js 就可能被拆开,最后构建出来的 chunkMap 中可能就找不到 umi.js 了
minChunks: 1, // 模块至少使用次数
maxAsyncRequests: 30, // 同时加载的模块数量最多是_个,只分割出同时引入的前_个文件(按需加载模块)
maxInitialRequests: 25, // 首页加载的时候引入的文件最多 _ 个(加载初始页面)
automaticNameDelimiter: '~', // 缓存组和生成文件名称之间的连接符
name: true, // 缓存组里面的 filename 生效,覆盖默认命名
cacheGroups: {
markdown_preview: {
name: 'vendors-markdown-preview',
chunks: 'all',
test: /[\\/]node_modules[\\/](@uiw\/react-markdown-preview|codemirror)[\\/]/,
priority: -2,
},
prismjs: {
name: 'vendors-prismjs',
chunks: 'all',
test: /[\\/]node_modules[\\/](prismjs)[\\/]/,
priority: -2,
},
react_code_preview: {
name: 'vendors-code-preview',
chunks: 'all',
test: /[\\/]node_modules[\\/](@uiw\/react-code-preview)[\\/]/,
priority: -2,
},
react: {
name: 'vendors-react',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom|react-router-dom)[\\/]/,
priority: -5,
},
lodash: {
name: 'vendors-lodash',
chunks: 'all',
test: /[\\/]node_modules[\\/](lodash)[\\/]/,
priority: -5,
},
babel_plugin: {
name: 'babel_plugin',
chunks: 'all',
// test: /[\\/]node_modules[\\/](babel-plugin-transform-remove-imports)[\\/]/,
test: /[\\/]node_modules[\\/](babel-?.*)[\\/]/,
priority: -5,
},
// babel_runtime: {
// name: 'vendors-runtime',
// chunks: 'all',
// test: /[\\/]node_modules[\\/](@babel)[\\/]/,
// priority: -5,
// },
babel_standalone: {
name: 'vendors-standalone',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/standalone)[\\/]/,
priority: -5,
},
babel_runtime_template: {
name: 'vendors-runtime-template',
chunks: 'all',
test: /[\\/]node_modules[\\/]@babel[\/](template|regenerator|highlight|parser|code-frame|plugin-transform-classes)[\\/]/,
priority: -5,
},
babel_runtime_core: {
name: 'vendors-runtime-core',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/core)[\\/]/,
priority: -5,
},
babel_remark: {
name: 'vendors-remark',
chunks: 'all',
test: /[\\/]node_modules[\\/](remark-parse)[\\/]/,
priority: -5,
},
babel_runtime_generator: {
name: 'vendors-runtime-generator',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/generator)[\\/]/,
priority: -5,
},
babel_helper: {
name: 'vendors-helper',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/helper?.*)[\\/]/,
priority: -5,
},
babel_runtime_helpers: {
name: 'vendors-runtime-helpers',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/runtime\/helpers)[\\/]/,
priority: -5,
},
babel_runtime_types: {
name: 'vendors-runtime-types',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/types)[\\/]/,
priority: -5,
},
babel_runtime_traverse: {
name: 'vendors-runtime-traverse',
chunks: 'all',
test: /[\\/]node_modules[\\/](@babel\/traverse)[\\/]/,
priority: -5,
if (env === 'production') {
conf.output = { ...conf.output, publicPath: './' };
conf.optimization = {
...conf.optimization,
splitChunks: {
cacheGroups: {
reactvendor: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'react-vendor',
chunks: 'all',
},
babelstandalone: {
test: /[\\/]node_modules[\\/](@babel[\\/]standalone)[\\/]/,
name: 'babel-standalone-vendor',
chunks: 'all',
},
prismjs: {
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
name: 'refractor-vendor',
chunks: 'all',
},
codemirror: {
test: /[\\/]node_modules[\\/](@codemirror)[\\/]/,
name: 'codemirror-vendor',
chunks: 'all',
},
uiw: {
test: /[\\/]node_modules[\\/](@uiw)[\\/]/,
name: 'uiw-vendor',
chunks: 'all',
},
parse5: {
test: /[\\/]node_modules[\\/](parse5)[\\/]/,
name: 'parse5-vendor',
chunks: 'all',
},
},
},
},
};
};
}

return conf;
}
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@
"react-dom": ">=16.8.0"
},
"devDependencies": {
"@kkt/less-modules": "6.11.0",
"@kkt/raw-modules": "6.11.0",
"@kkt/scope-plugin-options": "6.11.0",
"@types/react": "17.0.21",
"@types/react-dom": "17.0.9",
"@uiw/react-code-preview": "2.1.0",
"@kkt/less-modules": "7.0.5",
"@kkt/raw-modules": "7.0.5",
"@kkt/scope-plugin-options": "7.0.5",
"@types/react": "17.0.38",
"@types/react-dom": "17.0.11",
"@uiw/react-code-preview": "3.0.0",
"@uiw/react-github-corners": "1.5.3",
"@uiw/react-markdown-preview": "3.3.2",
"@uiw/reset.css": "1.0.5",
"compile-less-cli": "1.8.8",
"kkt": "6.11.0",
"rehype-attr": "2.0.2",
"compile-less-cli": "1.8.11",
"kkt": "7.0.5",
"react": "17.0.2",
"react-dom": "17.0.2",
"tsbb": "3.2.1",
"tsbb": "3.5.4",
"uiw": "4.9.7"
},
"eslintConfig": {
Expand Down

0 comments on commit c86f7cb

Please sign in to comment.