@shuvi/toolpack 1.0.38 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,7 +98,6 @@ function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot,
98
98
  emitOnErrors: !dev,
99
99
  checkWasmTypes: false,
100
100
  nodeEnv: false,
101
- splitChunks: false,
102
101
  runtimeChunk: undefined,
103
102
  minimize: !dev,
104
103
  realContentHash: false
@@ -36,7 +36,6 @@ const style_1 = require("./parts/style");
36
36
  const helpers_1 = require("./parts/helpers");
37
37
  const BIG_LIBRARY_THRESHOLD = 160000; // byte
38
38
  const SHUVI_PKGS_REGEX = /[\\/]node_modules[\\/](@shuvi|doura)[\\/]/;
39
- const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
40
39
  const FRAMEWORK_REACT_MODULES = [
41
40
  {
42
41
  test: /[/\\]node_modules[/\\]react[/\\]/
@@ -95,6 +94,8 @@ function createBrowserWebpackChain(options) {
95
94
  }
96
95
  if (dev) {
97
96
  chain.plugin('private/hmr-plugin').use(webpack_1.default.HotModuleReplacementPlugin);
97
+ // disable splitChunks at dev mode to prevent preload error
98
+ chain.optimization.splitChunks(false);
98
99
  }
99
100
  else {
100
101
  const getDefaultChunkName = (_module, chunks) => {
@@ -109,22 +110,8 @@ function createBrowserWebpackChain(options) {
109
110
  chain.optimization.splitChunks({
110
111
  chunks: helpers_1.splitChunksFilter,
111
112
  cacheGroups: {
112
- default: {
113
- name: getDefaultChunkName,
114
- filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
115
- idHint: '',
116
- reuseExistingChunk: true,
117
- minChunks: 2,
118
- priority: -20
119
- },
120
- defaultVendors: {
121
- name: getDefaultChunkName,
122
- filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
123
- idHint: 'vendors',
124
- reuseExistingChunk: true,
125
- test: NODE_MODULES_REGEXP,
126
- priority: -10
127
- },
113
+ default: Object.assign({ name: getDefaultChunkName, filename: (0, helpers_1.commonChunkFilename)({ dev: false }) }, helpers_1.defaultCacheGroups.default),
114
+ defaultVendors: Object.assign({ name: getDefaultChunkName, filename: (0, helpers_1.commonChunkFilename)({ dev: false }) }, helpers_1.defaultCacheGroups.defaultVendors),
128
115
  framework: {
129
116
  chunks: 'all',
130
117
  name: 'framework',
@@ -168,7 +155,7 @@ function createBrowserWebpackChain(options) {
168
155
  lib: {
169
156
  test(module) {
170
157
  return (module.size() > BIG_LIBRARY_THRESHOLD &&
171
- NODE_MODULES_REGEXP.test(module.nameForCondition() || ''));
158
+ helpers_1.NODE_MODULES_REGEXP.test(module.nameForCondition() || ''));
172
159
  },
173
160
  name(module) {
174
161
  const hash = crypto.createHash('sha1');
@@ -24,6 +24,8 @@ function createNodeWebpackChain(options) {
24
24
  chain.resolve.mainFields.clear().add('main').add('module');
25
25
  chain.output.libraryTarget('commonjs2');
26
26
  chain.optimization.minimize(false);
27
+ // use default splitChunks config
28
+ chain.optimization.splitChunks((0, helpers_1.getDefaultSplitChunksConfig)(dev));
27
29
  (0, helpers_1.addExternals)(chain, (0, external_1.nodeExternals)({
28
30
  projectRoot: options.projectRoot,
29
31
  include: options.include
@@ -7,3 +7,43 @@ export declare function splitChunksFilter(chunk: any): boolean;
7
7
  export declare const commonChunkFilename: ({ dev }: {
8
8
  dev: boolean;
9
9
  }) => string;
10
+ export declare const NODE_MODULES_REGEXP: RegExp;
11
+ export declare const defaultCacheGroups: {
12
+ default: {
13
+ idHint: string;
14
+ reuseExistingChunk: boolean;
15
+ minChunks: number;
16
+ priority: number;
17
+ };
18
+ defaultVendors: {
19
+ idHint: string;
20
+ reuseExistingChunk: boolean;
21
+ test: RegExp;
22
+ priority: number;
23
+ };
24
+ };
25
+ /** default splitChunks config https://github.com/webpack/webpack/blob/v5.73.0/lib/config/defaults.js#L1181 */
26
+ export declare const getDefaultSplitChunksConfig: (dev: boolean) => {
27
+ chunks: string;
28
+ minChunks: number;
29
+ minSize: number;
30
+ minRemainingSize: number | undefined;
31
+ enforceSizeThreshold: number;
32
+ maxAsyncRequests: number;
33
+ maxInitialRequests: number;
34
+ automaticNameDelimiter: string;
35
+ cacheGroups: {
36
+ default: {
37
+ idHint: string;
38
+ reuseExistingChunk: boolean;
39
+ minChunks: number;
40
+ priority: number;
41
+ };
42
+ defaultVendors: {
43
+ idHint: string;
44
+ reuseExistingChunk: boolean;
45
+ test: RegExp;
46
+ priority: number;
47
+ };
48
+ };
49
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.commonChunkFilename = exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.addExternals = exports.checkWebpackExternals = void 0;
6
+ exports.getDefaultSplitChunksConfig = exports.defaultCacheGroups = exports.NODE_MODULES_REGEXP = exports.commonChunkFilename = exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.addExternals = exports.checkWebpackExternals = void 0;
7
7
  const invariant_1 = __importDefault(require("@shuvi/utils/invariant"));
8
8
  const externalsFunctionMap = new WeakMap();
9
9
  const checkWebpackExternals = (webpackChain) => {
@@ -74,3 +74,33 @@ const commonChunkFilename = ({ dev }) => {
74
74
  return `static/common/${dev ? '[name]' : '[name].[contenthash:8]'}.js`;
75
75
  };
76
76
  exports.commonChunkFilename = commonChunkFilename;
77
+ exports.NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
78
+ exports.defaultCacheGroups = {
79
+ default: {
80
+ idHint: '',
81
+ reuseExistingChunk: true,
82
+ minChunks: 2,
83
+ priority: -20
84
+ },
85
+ defaultVendors: {
86
+ idHint: 'vendors',
87
+ reuseExistingChunk: true,
88
+ test: exports.NODE_MODULES_REGEXP,
89
+ priority: -10
90
+ }
91
+ };
92
+ /** default splitChunks config https://github.com/webpack/webpack/blob/v5.73.0/lib/config/defaults.js#L1181 */
93
+ const getDefaultSplitChunksConfig = (dev) => {
94
+ return {
95
+ chunks: 'async',
96
+ minChunks: 1,
97
+ minSize: dev ? 10000 : 20000,
98
+ minRemainingSize: dev ? 0 : undefined,
99
+ enforceSizeThreshold: dev ? 30000 : 50000,
100
+ maxAsyncRequests: dev ? Infinity : 30,
101
+ maxInitialRequests: dev ? Infinity : 30,
102
+ automaticNameDelimiter: '-',
103
+ cacheGroups: exports.defaultCacheGroups
104
+ };
105
+ };
106
+ exports.getDefaultSplitChunksConfig = getDefaultSplitChunksConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "1.0.38",
3
+ "version": "1.0.41",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -20,7 +20,7 @@
20
20
  "node": ">= 16.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@shuvi/compiler": "1.0.38",
23
+ "@shuvi/compiler": "1.0.41",
24
24
  "@babel/core": "7.12.10",
25
25
  "@babel/plugin-proposal-class-properties": "7.12.1",
26
26
  "@babel/plugin-proposal-nullish-coalescing-operator": "7.10.1",
@@ -35,8 +35,8 @@
35
35
  "@babel/preset-typescript": "7.12.7",
36
36
  "@babel/runtime": "7.12.5",
37
37
  "lightningcss": "1.19.0",
38
- "@shuvi/shared": "1.0.38",
39
- "@shuvi/utils": "1.0.38",
38
+ "@shuvi/shared": "1.0.41",
39
+ "@shuvi/utils": "1.0.41",
40
40
  "babel-loader": "8.2.2",
41
41
  "babel-plugin-syntax-jsx": "6.18.0",
42
42
  "babel-plugin-transform-define": "2.0.0",