@shuvi/toolpack 1.0.0-rc.8 → 1.0.0-rc.9
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.
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppSourceRegexs = void 0;
|
|
3
|
+
exports.CommonChunkFilename = exports.AppSourceRegexs = void 0;
|
|
4
4
|
exports.AppSourceRegexs = [
|
|
5
5
|
/([/\\]shuvi-app[/\\])|([/\\]\.shuvi[/\\])/
|
|
6
6
|
];
|
|
7
|
+
exports.CommonChunkFilename = 'static/common/[name].js';
|
|
@@ -35,12 +35,12 @@ const webpack_1 = __importDefault(require("webpack"));
|
|
|
35
35
|
const path = __importStar(require("path"));
|
|
36
36
|
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
37
37
|
const build_manifest_plugin_1 = __importDefault(require("../plugins/build-manifest-plugin"));
|
|
38
|
-
const chunk_names_plugin_1 = __importDefault(require("../plugins/chunk-names-plugin"));
|
|
39
38
|
const fix_watching_plugin_1 = __importDefault(require("../plugins/fix-watching-plugin"));
|
|
40
39
|
const constants_2 = require("../../constants");
|
|
41
40
|
const crypto = __importStar(require("crypto"));
|
|
42
41
|
const jsconfig_paths_plugin_1 = __importDefault(require("../plugins/jsconfig-paths-plugin"));
|
|
43
42
|
const support_ts_extension_resolver_plugin_1 = __importDefault(require("../plugins/support-ts-extension-resolver-plugin"));
|
|
43
|
+
const helpers_1 = require("./parts/helpers");
|
|
44
44
|
const resolveLocalLoader = (name) => path.join(__dirname, `../loaders/${name}`);
|
|
45
45
|
const terserOptions = {
|
|
46
46
|
parse: {
|
|
@@ -68,16 +68,47 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
68
68
|
config.bail(!dev);
|
|
69
69
|
config.performance.hints(false);
|
|
70
70
|
config.context(projectRoot);
|
|
71
|
+
config.output.path(outputDir);
|
|
72
|
+
config.output.merge({
|
|
73
|
+
publicPath,
|
|
74
|
+
filename: `${dev ? '[name].js' : '[name].[contenthash:8]'}.js`,
|
|
75
|
+
// This saves chunks with the name given via `import()`
|
|
76
|
+
chunkFilename: `static/chunks/${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
77
|
+
hotUpdateChunkFilename: 'static/webpack/[id].[fullhash].hot-update.js',
|
|
78
|
+
hotUpdateMainFilename: 'static/webpack/[fullhash].hot-update.json',
|
|
79
|
+
strictModuleExceptionHandling: true,
|
|
80
|
+
// crossOriginLoading: crossOrigin,
|
|
81
|
+
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
|
|
82
|
+
hashFunction: 'xxhash64',
|
|
83
|
+
hashDigestLength: 16
|
|
84
|
+
});
|
|
71
85
|
config.optimization.merge({
|
|
72
86
|
emitOnErrors: !dev,
|
|
73
87
|
checkWasmTypes: false,
|
|
74
88
|
nodeEnv: false,
|
|
75
|
-
splitChunks: false,
|
|
76
89
|
runtimeChunk: undefined,
|
|
77
90
|
minimize: !dev,
|
|
78
91
|
realContentHash: false
|
|
79
92
|
});
|
|
80
|
-
if (
|
|
93
|
+
if (dev) {
|
|
94
|
+
config.optimization.usedExports(false);
|
|
95
|
+
config.optimization.splitChunks({
|
|
96
|
+
chunks: helpers_1.splitChunksFilter,
|
|
97
|
+
cacheGroups: {
|
|
98
|
+
defaultVendors: false,
|
|
99
|
+
default: false,
|
|
100
|
+
vendors: {
|
|
101
|
+
name: 'vendors',
|
|
102
|
+
filename: constants_2.CommonChunkFilename,
|
|
103
|
+
test: /[\\/]node_modules[\\/]/,
|
|
104
|
+
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
105
|
+
// becoming a part of the commons chunk)
|
|
106
|
+
enforce: true
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
81
112
|
// @ts-ignore
|
|
82
113
|
config.optimization.minimizer('terser').use(terser_webpack_plugin_1.default, [
|
|
83
114
|
{
|
|
@@ -95,20 +126,6 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
95
126
|
}
|
|
96
127
|
]);
|
|
97
128
|
}
|
|
98
|
-
config.output.path(outputDir);
|
|
99
|
-
config.output.merge({
|
|
100
|
-
publicPath,
|
|
101
|
-
filename: `${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
102
|
-
// This saves chunks with the name given via `import()`
|
|
103
|
-
chunkFilename: `static/chunks/${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
104
|
-
hotUpdateChunkFilename: 'static/webpack/[id].[fullhash].hot-update.js',
|
|
105
|
-
hotUpdateMainFilename: 'static/webpack/[fullhash].hot-update.json',
|
|
106
|
-
strictModuleExceptionHandling: true,
|
|
107
|
-
// crossOriginLoading: crossOrigin,
|
|
108
|
-
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
|
|
109
|
-
hashFunction: 'xxhash64',
|
|
110
|
-
hashDigestLength: 16
|
|
111
|
-
});
|
|
112
129
|
// Support for NODE_PATH
|
|
113
130
|
const nodePathList = (process.env.NODE_PATH || '')
|
|
114
131
|
.split(process.platform === 'win32' ? ';' : ':')
|
|
@@ -162,7 +179,6 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
162
179
|
.options({
|
|
163
180
|
name: 'static/media/[name].[hash:8].[ext]'
|
|
164
181
|
});
|
|
165
|
-
config.plugin('chunk-names').use(chunk_names_plugin_1.default);
|
|
166
182
|
config.plugin('private/ignore-plugin').use(webpack_1.default.IgnorePlugin, [
|
|
167
183
|
{
|
|
168
184
|
resourceRegExp: /^\.\/locale$/,
|
|
@@ -232,7 +248,6 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
232
248
|
level: 'none'
|
|
233
249
|
});
|
|
234
250
|
config.plugin('private/fix-watching-plugin').use(fix_watching_plugin_1.default);
|
|
235
|
-
config.optimization.usedExports(false);
|
|
236
251
|
}
|
|
237
252
|
else {
|
|
238
253
|
config
|
|
@@ -32,9 +32,12 @@ const webpack_1 = __importDefault(require("webpack"));
|
|
|
32
32
|
const path = __importStar(require("path"));
|
|
33
33
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
34
34
|
const resolve_1 = require("@shuvi/utils/lib/resolve");
|
|
35
|
+
// import PreferResolverPlugin from '../plugins/prefer-resolver-plugin';
|
|
36
|
+
const constants_1 = require("../../constants");
|
|
35
37
|
const dynamic_public_path_plugin_1 = __importDefault(require("../plugins/dynamic-public-path-plugin"));
|
|
36
38
|
const base_1 = require("./base");
|
|
37
39
|
const style_1 = require("./parts/style");
|
|
40
|
+
const helpers_1 = require("./parts/helpers");
|
|
38
41
|
const BIG_LIBRARY_THRESHOLD = 160000; // byte
|
|
39
42
|
function createBrowserWebpackChain(options) {
|
|
40
43
|
const { cacheDir, typescript, dev, publicPath, analyze } = options;
|
|
@@ -89,17 +92,24 @@ function createBrowserWebpackChain(options) {
|
|
|
89
92
|
}
|
|
90
93
|
else {
|
|
91
94
|
chain.optimization.splitChunks({
|
|
92
|
-
chunks:
|
|
95
|
+
chunks: helpers_1.splitChunksFilter,
|
|
93
96
|
cacheGroups: {
|
|
94
97
|
default: false,
|
|
95
98
|
defaultVendors: false,
|
|
96
99
|
framework: {
|
|
97
100
|
chunks: 'all',
|
|
98
101
|
name: 'framework',
|
|
102
|
+
filename: constants_1.CommonChunkFilename,
|
|
99
103
|
// This regex ignores nested copies of framework libraries so they're
|
|
100
104
|
// bundled with their issuer.
|
|
101
105
|
// https://github.com/zeit/next.js/pull/9012
|
|
102
|
-
test
|
|
106
|
+
test(module) {
|
|
107
|
+
const resource = module.nameForCondition();
|
|
108
|
+
return resource
|
|
109
|
+
? ['@shuvi/redox-react', 'react', 'react-dom'].some(pkg => resource.indexOf(pkg) >= 0)
|
|
110
|
+
: false;
|
|
111
|
+
},
|
|
112
|
+
// test: /(?<!node_modules.*)[\\/]node_modules[\\/](react|react-dom|@shuvi[\\/]router|@shuvi[\\/]router-react|scheduler|prop-types|use-sync-external-store|history)[\\/]/,
|
|
103
113
|
priority: 40,
|
|
104
114
|
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
105
115
|
// becoming a part of the commons chunk)
|
|
@@ -108,7 +118,7 @@ function createBrowserWebpackChain(options) {
|
|
|
108
118
|
lib: {
|
|
109
119
|
test(module) {
|
|
110
120
|
return (module.size() > BIG_LIBRARY_THRESHOLD &&
|
|
111
|
-
/node_modules[/\\]/.test(module.
|
|
121
|
+
/node_modules[/\\]/.test(module.nameForCondition() || ''));
|
|
112
122
|
},
|
|
113
123
|
name(module) {
|
|
114
124
|
const hash = crypto.createHash('sha1');
|
|
@@ -123,27 +133,10 @@ function createBrowserWebpackChain(options) {
|
|
|
123
133
|
}
|
|
124
134
|
return hash.digest('hex').substring(0, 8);
|
|
125
135
|
},
|
|
136
|
+
filename: constants_1.CommonChunkFilename,
|
|
126
137
|
priority: 30,
|
|
127
138
|
minChunks: 1,
|
|
128
139
|
reuseExistingChunk: true
|
|
129
|
-
},
|
|
130
|
-
commons: {
|
|
131
|
-
name: 'commons',
|
|
132
|
-
minChunks: 2,
|
|
133
|
-
priority: 20
|
|
134
|
-
},
|
|
135
|
-
shared: {
|
|
136
|
-
name(module, chunks) {
|
|
137
|
-
return crypto
|
|
138
|
-
.createHash('sha1')
|
|
139
|
-
.update(chunks.reduce((acc, chunk) => {
|
|
140
|
-
return acc + chunk.name;
|
|
141
|
-
}, ''))
|
|
142
|
-
.digest('hex');
|
|
143
|
-
},
|
|
144
|
-
priority: 10,
|
|
145
|
-
minChunks: 2,
|
|
146
|
-
reuseExistingChunk: true
|
|
147
140
|
}
|
|
148
141
|
},
|
|
149
142
|
maxInitialRequests: 25,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
|
|
3
|
+
exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
|
|
4
4
|
const webpackHelpers = () => {
|
|
5
5
|
const externalFns = [];
|
|
6
6
|
const defaultExternalsFn = ({ context, request }, callback) => {
|
|
@@ -48,3 +48,10 @@ function shouldUseRelativeAssetPaths(publicPath) {
|
|
|
48
48
|
return publicPath === './';
|
|
49
49
|
}
|
|
50
50
|
exports.shouldUseRelativeAssetPaths = shouldUseRelativeAssetPaths;
|
|
51
|
+
function splitChunksFilter(chunk) {
|
|
52
|
+
const excludes = {
|
|
53
|
+
'static/polyfill': true
|
|
54
|
+
};
|
|
55
|
+
return excludes[chunk.name] !== true;
|
|
56
|
+
}
|
|
57
|
+
exports.splitChunksFilter = splitChunksFilter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/toolpack",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node": ">= 12.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@shuvi/compiler": "1.0.0-rc.
|
|
23
|
+
"@shuvi/compiler": "1.0.0-rc.9",
|
|
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
|
"@parcel/css": "1.2.0",
|
|
38
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
39
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
38
|
+
"@shuvi/shared": "1.0.0-rc.9",
|
|
39
|
+
"@shuvi/utils": "1.0.0-rc.9",
|
|
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",
|