@shuvi/toolpack 1.0.0-rc.8 → 1.0.0
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/utils/{bundle-require.d.ts → bundleRequire.d.ts} +0 -0
- package/lib/utils/{bundle-require.js → bundleRequire.js} +1 -1
- package/lib/webpack/config/base.d.ts +10 -6
- package/lib/webpack/config/base.js +66 -51
- package/lib/webpack/config/browser.js +50 -35
- package/lib/webpack/config/node.js +1 -4
- package/lib/webpack/config/parts/external.d.ts +1 -1
- package/lib/webpack/config/parts/external.js +1 -8
- package/lib/webpack/config/parts/helpers.d.ts +4 -0
- package/lib/webpack/config/parts/helpers.js +12 -1
- package/lib/webpack/config/parts/style.d.ts +2 -2
- package/lib/webpack/config/parts/style.js +42 -35
- package/lib/webpack/index.d.ts +3 -13
- package/lib/webpack/index.js +24 -104
- package/lib/webpack/loaders/async-import-loader.d.ts +6 -0
- package/lib/webpack/loaders/async-import-loader.js +19 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/CssSyntaxError.d.ts +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/CssSyntaxError.js +0 -0
- package/lib/webpack/loaders/lightningcss-loader/index.d.ts +4 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/index.js +50 -48
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/api.d.ts +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/api.js +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/getUrl.d.ts +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/getUrl.js +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/noSourceMaps.d.ts +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/noSourceMaps.js +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/sourceMaps.d.ts +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/runtime/sourceMaps.js +0 -0
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/utils.d.ts +5 -2
- package/lib/webpack/loaders/{parcel-css-loader → lightningcss-loader}/utils.js +17 -8
- package/lib/webpack/loaders/route-component-loader.d.ts +2 -2
- package/lib/webpack/loaders/route-component-loader.js +2 -26
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +65 -19
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +17 -14
- package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +5 -2
- package/lib/webpack/loaders/shuvi-swc-loader/index.js +10 -45
- package/lib/webpack/plugins/copy-file-plugin.d.ts +14 -0
- package/lib/webpack/plugins/copy-file-plugin.js +87 -0
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +3 -2
- package/lib/webpack/plugins/module-replace-plugin/stub-loader.d.ts +5 -1
- package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +10 -30
- package/lib/webpack/types.d.ts +1 -0
- package/lib/webpack/webpack.d.ts +11 -0
- package/lib/webpack/webpack.js +103 -0
- package/package.json +9 -9
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +0 -6
- package/lib/webpack/loaders/parcel-css-loader/index.d.ts +0 -4
- package/lib/webpack/plugins/build-manifest-plugin.d.ts +0 -27
- package/lib/webpack/plugins/build-manifest-plugin.js +0 -215
|
File without changes
|
|
@@ -130,7 +130,7 @@ function bundleRequire(filepath, options = {}) {
|
|
|
130
130
|
}
|
|
131
131
|
return mod;
|
|
132
132
|
});
|
|
133
|
-
const result = yield (0, esbuild_1.build)(Object.assign(Object.assign({}, options.esbuildOptions), { entryPoints: [filepath], absWorkingDir: cwd, outfile, format: 'cjs', platform: 'node', sourcemap: 'inline', bundle: true, metafile: true, write: true, watch: false, plugins: [
|
|
133
|
+
const result = yield (0, esbuild_1.build)(Object.assign(Object.assign({}, options.esbuildOptions), { entryPoints: [filepath], absWorkingDir: cwd, outfile, format: 'cjs', target: 'es6', platform: 'node', sourcemap: 'inline', bundle: true, metafile: true, write: true, watch: false, plugins: [
|
|
134
134
|
...(((_b = options.esbuildOptions) === null || _b === void 0 ? void 0 : _b.plugins) || []),
|
|
135
135
|
(0, exports.externalPlugin)({
|
|
136
136
|
external: options.external
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import WebpackChain from 'webpack-chain';
|
|
2
|
+
import { CompilerOptions } from '../loaders/shuvi-swc-loader';
|
|
2
3
|
declare type TsCompilerOptions = import('typescript').CompilerOptions;
|
|
3
4
|
export interface BaseOptions {
|
|
4
5
|
dev: boolean;
|
|
5
|
-
parcelCss: boolean;
|
|
6
6
|
name: string;
|
|
7
7
|
projectRoot: string;
|
|
8
8
|
outputDir: string;
|
|
9
9
|
cacheDir: string;
|
|
10
|
-
include: string[];
|
|
10
|
+
include: (string | RegExp)[];
|
|
11
11
|
typescript?: {
|
|
12
12
|
useTypeScript: boolean;
|
|
13
13
|
typeScriptPath?: string;
|
|
@@ -15,14 +15,18 @@ export interface BaseOptions {
|
|
|
15
15
|
tsCompilerOptions?: TsCompilerOptions;
|
|
16
16
|
resolvedBaseUrl?: string;
|
|
17
17
|
};
|
|
18
|
-
buildManifestFilename: string;
|
|
19
18
|
target?: string;
|
|
20
19
|
publicPath?: string;
|
|
21
20
|
env?: {
|
|
22
21
|
[x: string]: string | undefined;
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
compiler?:
|
|
23
|
+
lightningCss?: boolean;
|
|
24
|
+
compiler?: CompilerOptions;
|
|
26
25
|
}
|
|
27
26
|
export { WebpackChain };
|
|
28
|
-
export declare function
|
|
27
|
+
export declare function getDefineEnv(env: {
|
|
28
|
+
[x: string]: string | undefined;
|
|
29
|
+
}): {
|
|
30
|
+
[x: string]: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, typescript, name, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.baseWebpackChain = exports.WebpackChain = void 0;
|
|
29
|
+
exports.baseWebpackChain = exports.getDefineEnv = exports.WebpackChain = void 0;
|
|
30
30
|
const webpack_chain_1 = __importDefault(require("webpack-chain"));
|
|
31
31
|
exports.WebpackChain = webpack_chain_1.default;
|
|
32
32
|
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
|
@@ -34,13 +34,11 @@ const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-we
|
|
|
34
34
|
const webpack_1 = __importDefault(require("webpack"));
|
|
35
35
|
const path = __importStar(require("path"));
|
|
36
36
|
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
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
37
|
const fix_watching_plugin_1 = __importDefault(require("../plugins/fix-watching-plugin"));
|
|
40
|
-
const constants_2 = require("../../constants");
|
|
41
38
|
const crypto = __importStar(require("crypto"));
|
|
42
39
|
const jsconfig_paths_plugin_1 = __importDefault(require("../plugins/jsconfig-paths-plugin"));
|
|
43
40
|
const support_ts_extension_resolver_plugin_1 = __importDefault(require("../plugins/support-ts-extension-resolver-plugin"));
|
|
41
|
+
const helpers_1 = require("./parts/helpers");
|
|
44
42
|
const resolveLocalLoader = (name) => path.join(__dirname, `../loaders/${name}`);
|
|
45
43
|
const terserOptions = {
|
|
46
44
|
parse: {
|
|
@@ -61,23 +59,68 @@ const terserOptions = {
|
|
|
61
59
|
ascii_only: true
|
|
62
60
|
}
|
|
63
61
|
};
|
|
64
|
-
function
|
|
62
|
+
function getDefineEnv(env) {
|
|
63
|
+
return Object.assign(Object.assign({}, Object.keys(process.env).reduce((prev, key) => {
|
|
64
|
+
if (key.startsWith(constants_1.PUBLIC_ENV_PREFIX)) {
|
|
65
|
+
prev[`process.env.${key}`] = JSON.stringify(process.env[key]);
|
|
66
|
+
}
|
|
67
|
+
return prev;
|
|
68
|
+
}, {})), Object.keys(env).reduce((acc, key) => {
|
|
69
|
+
if (/^(?:NODE_.+)|^(?:__.+)$/i.test(key)) {
|
|
70
|
+
throw new Error(`The key "${key}" under "env" is not allowed.`);
|
|
71
|
+
}
|
|
72
|
+
return Object.assign(Object.assign({}, acc), { [`process.env.${key}`]: JSON.stringify(env[key]) });
|
|
73
|
+
}, {}));
|
|
74
|
+
}
|
|
75
|
+
exports.getDefineEnv = getDefineEnv;
|
|
76
|
+
function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, typescript, name, publicPath = '/', env = {}, cacheDir }) {
|
|
65
77
|
var _a;
|
|
66
78
|
const config = new webpack_chain_1.default();
|
|
67
79
|
config.mode(dev ? 'development' : 'production');
|
|
68
80
|
config.bail(!dev);
|
|
69
81
|
config.performance.hints(false);
|
|
70
82
|
config.context(projectRoot);
|
|
83
|
+
config.output.path(outputDir);
|
|
84
|
+
config.output.merge({
|
|
85
|
+
publicPath,
|
|
86
|
+
filename: `${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
87
|
+
// This saves chunks with the name given via `import()`
|
|
88
|
+
chunkFilename: `static/chunks/${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
89
|
+
hotUpdateChunkFilename: 'static/webpack/[id].[fullhash].hot-update.js',
|
|
90
|
+
hotUpdateMainFilename: 'static/webpack/[runtime].[fullhash].hot-update.json',
|
|
91
|
+
strictModuleExceptionHandling: true,
|
|
92
|
+
// crossOriginLoading: crossOrigin,
|
|
93
|
+
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
|
|
94
|
+
hashFunction: 'xxhash64',
|
|
95
|
+
hashDigestLength: 16
|
|
96
|
+
});
|
|
71
97
|
config.optimization.merge({
|
|
72
98
|
emitOnErrors: !dev,
|
|
73
99
|
checkWasmTypes: false,
|
|
74
100
|
nodeEnv: false,
|
|
75
|
-
splitChunks: false,
|
|
76
101
|
runtimeChunk: undefined,
|
|
77
102
|
minimize: !dev,
|
|
78
103
|
realContentHash: false
|
|
79
104
|
});
|
|
80
|
-
if (
|
|
105
|
+
if (dev) {
|
|
106
|
+
config.optimization.usedExports(false);
|
|
107
|
+
config.optimization.splitChunks({
|
|
108
|
+
chunks: helpers_1.splitChunksFilter,
|
|
109
|
+
cacheGroups: {
|
|
110
|
+
defaultVendors: false,
|
|
111
|
+
default: false,
|
|
112
|
+
vendors: {
|
|
113
|
+
name: 'vendors',
|
|
114
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: true }),
|
|
115
|
+
test: /[\\/]node_modules[\\/]/,
|
|
116
|
+
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
117
|
+
// becoming a part of the commons chunk)
|
|
118
|
+
enforce: true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
81
124
|
// @ts-ignore
|
|
82
125
|
config.optimization.minimizer('terser').use(terser_webpack_plugin_1.default, [
|
|
83
126
|
{
|
|
@@ -89,26 +132,12 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
89
132
|
config.optimization.minimizer('cssMinimizer').use(css_minimizer_webpack_plugin_1.default, [
|
|
90
133
|
{
|
|
91
134
|
// @ts-ignore
|
|
92
|
-
minify:
|
|
93
|
-
? css_minimizer_webpack_plugin_1.default.
|
|
135
|
+
minify: lightningCss
|
|
136
|
+
? css_minimizer_webpack_plugin_1.default.lightningCssMinify
|
|
94
137
|
: css_minimizer_webpack_plugin_1.default.cssnanoMinify
|
|
95
138
|
}
|
|
96
139
|
]);
|
|
97
140
|
}
|
|
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
141
|
// Support for NODE_PATH
|
|
113
142
|
const nodePathList = (process.env.NODE_PATH || '')
|
|
114
143
|
.split(process.platform === 'win32' ? ';' : ':')
|
|
@@ -117,14 +146,14 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
117
146
|
modules: [
|
|
118
147
|
'node_modules',
|
|
119
148
|
...nodePathList // Support for NODE_PATH environment variable
|
|
120
|
-
]
|
|
121
|
-
alias: {}
|
|
149
|
+
]
|
|
122
150
|
});
|
|
151
|
+
config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
|
|
123
152
|
config.resolveLoader.merge({
|
|
124
153
|
alias: [
|
|
154
|
+
'lightningcss-loader',
|
|
125
155
|
'shuvi-swc-loader',
|
|
126
|
-
'route-component-loader'
|
|
127
|
-
'parcel-css-loader'
|
|
156
|
+
'route-component-loader'
|
|
128
157
|
].reduce((alias, loader) => {
|
|
129
158
|
alias[`@shuvi/${loader}`] = resolveLocalLoader(loader);
|
|
130
159
|
return alias;
|
|
@@ -141,18 +170,16 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
141
170
|
mainRule
|
|
142
171
|
.oneOf('js')
|
|
143
172
|
.test(/\.(tsx|ts|js|cjs|mjs|jsx)$/)
|
|
144
|
-
.include.merge([...include
|
|
173
|
+
.include.merge([...include])
|
|
145
174
|
.end()
|
|
146
175
|
.use('shuvi-swc-loader')
|
|
147
176
|
.loader('@shuvi/shuvi-swc-loader')
|
|
148
177
|
.options({
|
|
149
178
|
isServer: false,
|
|
150
|
-
experimental,
|
|
151
179
|
compiler,
|
|
152
180
|
supportedBrowsers: false,
|
|
153
181
|
swcCacheDir: path.join(cacheDir, 'swc')
|
|
154
182
|
});
|
|
155
|
-
config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
|
|
156
183
|
mainRule
|
|
157
184
|
.oneOf('media')
|
|
158
185
|
.exclude.merge([/\.(tsx|ts|js|cjs|mjs|jsx)$/, /\.html$/, /\.json$/])
|
|
@@ -162,39 +189,28 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
162
189
|
.options({
|
|
163
190
|
name: 'static/media/[name].[hash:8].[ext]'
|
|
164
191
|
});
|
|
165
|
-
config.plugin('chunk-names').use(chunk_names_plugin_1.default);
|
|
166
192
|
config.plugin('private/ignore-plugin').use(webpack_1.default.IgnorePlugin, [
|
|
167
193
|
{
|
|
168
194
|
resourceRegExp: /^\.\/locale$/,
|
|
169
195
|
contextRegExp: /moment$/
|
|
170
196
|
}
|
|
171
197
|
]);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return prev;
|
|
177
|
-
}, {});
|
|
178
|
-
const shuviConfigEnv = Object.keys(env).reduce((acc, key) => {
|
|
179
|
-
if (/^(?:NODE_.+)|^(?:__.+)$/i.test(key)) {
|
|
180
|
-
throw new Error(`The key "${key}" under "env" is not allowed.`);
|
|
181
|
-
}
|
|
182
|
-
return Object.assign(Object.assign({}, acc), { [`process.env.${key}`]: JSON.stringify(env[key]) });
|
|
183
|
-
}, {});
|
|
184
|
-
config.plugin('define').use(webpack_1.default.DefinePlugin, [
|
|
185
|
-
Object.assign(Object.assign(Object.assign({}, shuviPublicEnv), shuviConfigEnv), { 'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production') })
|
|
198
|
+
config.plugin('private/define').use(webpack_1.default.DefinePlugin, [
|
|
199
|
+
Object.assign({
|
|
200
|
+
// internal field to identify the plugin config
|
|
201
|
+
__SHUVI_DEFINE_ENV: 'true' }, getDefineEnv(env))
|
|
186
202
|
]);
|
|
187
|
-
config
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
203
|
+
config.plugin('define').use(webpack_1.default.DefinePlugin, [
|
|
204
|
+
{
|
|
205
|
+
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production')
|
|
206
|
+
}
|
|
191
207
|
]);
|
|
192
208
|
const getCacheConfig = () => {
|
|
193
209
|
const projectHash = crypto
|
|
194
210
|
.createHash('md5')
|
|
195
211
|
.update(projectRoot)
|
|
196
212
|
.digest('hex');
|
|
197
|
-
const stringifiedEnvs = Object.entries(Object.assign(
|
|
213
|
+
const stringifiedEnvs = Object.entries(Object.assign({}, getDefineEnv(env))).reduce((prev, [key, value]) => {
|
|
198
214
|
return `${prev}|${key}=${value}`;
|
|
199
215
|
}, '');
|
|
200
216
|
const PACKAGE_JSON = path.resolve(__dirname, '../../../package.json');
|
|
@@ -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,10 +32,23 @@ 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
|
-
const dynamic_public_path_plugin_1 = __importDefault(require("../plugins/dynamic-public-path-plugin"));
|
|
36
35
|
const base_1 = require("./base");
|
|
37
36
|
const style_1 = require("./parts/style");
|
|
37
|
+
const helpers_1 = require("./parts/helpers");
|
|
38
38
|
const BIG_LIBRARY_THRESHOLD = 160000; // byte
|
|
39
|
+
const SHUVI_PKGS_REGEX = /[\\/]node_modules[\\/]@shuvi[\\/]/;
|
|
40
|
+
const FRAMEWORK_REACT_MODULES = [
|
|
41
|
+
{
|
|
42
|
+
test: /[/\\]node_modules[/\\]react[/\\]/
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
test: /[/\\]node_modules[/\\]react-dom[/\\]/
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
test: /[/\\]node_modules[/\\]scheduler[/\\]/,
|
|
49
|
+
issuers: [/[/\\]node_modules[/\\]react-dom[/\\]/]
|
|
50
|
+
}
|
|
51
|
+
];
|
|
39
52
|
function createBrowserWebpackChain(options) {
|
|
40
53
|
const { cacheDir, typescript, dev, publicPath, analyze } = options;
|
|
41
54
|
const chain = (0, base_1.baseWebpackChain)(options);
|
|
@@ -79,27 +92,50 @@ function createBrowserWebpackChain(options) {
|
|
|
79
92
|
}
|
|
80
93
|
]);
|
|
81
94
|
}
|
|
82
|
-
// if (options.target) {
|
|
83
|
-
// chain.resolve
|
|
84
|
-
// .plugin('private/prefer-resolver-plugin')
|
|
85
|
-
// .use(PreferResolverPlugin, [{ suffix: options.target }]);
|
|
86
|
-
// }
|
|
87
95
|
if (dev) {
|
|
88
96
|
chain.plugin('private/hmr-plugin').use(webpack_1.default.HotModuleReplacementPlugin);
|
|
89
97
|
}
|
|
90
98
|
else {
|
|
91
99
|
chain.optimization.splitChunks({
|
|
92
|
-
chunks:
|
|
100
|
+
chunks: helpers_1.splitChunksFilter,
|
|
93
101
|
cacheGroups: {
|
|
94
102
|
default: false,
|
|
95
103
|
defaultVendors: false,
|
|
96
104
|
framework: {
|
|
97
105
|
chunks: 'all',
|
|
98
106
|
name: 'framework',
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
|
|
108
|
+
test(module, { moduleGraph }) {
|
|
109
|
+
const resource = module.nameForCondition();
|
|
110
|
+
if (!resource) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (SHUVI_PKGS_REGEX.test(resource)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return FRAMEWORK_REACT_MODULES.some(frameworkModule => {
|
|
117
|
+
if (!frameworkModule.test.test(resource)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// Check issuer to ignore nested copies of framework libraries so they're
|
|
121
|
+
// bundled with their issuer.
|
|
122
|
+
// https://github.com/zeit/next.js/pull/9012
|
|
123
|
+
if (frameworkModule.issuers) {
|
|
124
|
+
for (const issuerTest of frameworkModule.issuers) {
|
|
125
|
+
// fix: DeprecationWarning: Module.issuer: Use new ModuleGraph API
|
|
126
|
+
const issuer = moduleGraph.getIssuer(module);
|
|
127
|
+
const issuerResource = issuer
|
|
128
|
+
? issuer.nameForCondition()
|
|
129
|
+
: null;
|
|
130
|
+
if (!issuerResource || !issuerTest.test(issuerResource)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
// test: /(?<!node_modules.*)[\\/]node_modules[\\/](react|react-dom|@shuvi[\\/]router|@shuvi[\\/]router-react|scheduler|prop-types|use-sync-external-store|history)[\\/]/,
|
|
103
139
|
priority: 40,
|
|
104
140
|
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
105
141
|
// becoming a part of the commons chunk)
|
|
@@ -108,7 +144,7 @@ function createBrowserWebpackChain(options) {
|
|
|
108
144
|
lib: {
|
|
109
145
|
test(module) {
|
|
110
146
|
return (module.size() > BIG_LIBRARY_THRESHOLD &&
|
|
111
|
-
/node_modules[/\\]/.test(module.
|
|
147
|
+
/[/\\]node_modules[/\\]/.test(module.nameForCondition() || ''));
|
|
112
148
|
},
|
|
113
149
|
name(module) {
|
|
114
150
|
const hash = crypto.createHash('sha1');
|
|
@@ -123,27 +159,10 @@ function createBrowserWebpackChain(options) {
|
|
|
123
159
|
}
|
|
124
160
|
return hash.digest('hex').substring(0, 8);
|
|
125
161
|
},
|
|
162
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
|
|
126
163
|
priority: 30,
|
|
127
164
|
minChunks: 1,
|
|
128
165
|
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
166
|
}
|
|
148
167
|
},
|
|
149
168
|
maxInitialRequests: 25,
|
|
@@ -185,14 +204,10 @@ function createBrowserWebpackChain(options) {
|
|
|
185
204
|
// prevent errof of destructing process.env
|
|
186
205
|
'process.env': JSON.stringify('{}') })
|
|
187
206
|
]);
|
|
188
|
-
chain.plugin('dynamic-public-path-plugin').use(dynamic_public_path_plugin_1.default);
|
|
189
|
-
chain.plugin('private/build-manifest').tap(([options]) => [
|
|
190
|
-
Object.assign(Object.assign({}, options), { modules: true })
|
|
191
|
-
]);
|
|
192
207
|
return (0, style_1.withStyle)(chain, {
|
|
193
208
|
extractCss: !dev,
|
|
194
209
|
publicPath,
|
|
195
|
-
|
|
210
|
+
lightningCss: options.lightningCss,
|
|
196
211
|
filename: 'static/css/[contenthash:8].css',
|
|
197
212
|
chunkFilename: 'static/css/[contenthash:8].chunk.css'
|
|
198
213
|
});
|
|
@@ -32,15 +32,12 @@ function createNodeWebpackChain(options) {
|
|
|
32
32
|
.oneOf('js')
|
|
33
33
|
.use('shuvi-swc-loader')
|
|
34
34
|
.tap(options => (Object.assign(Object.assign({}, options), { isServer: true })));
|
|
35
|
-
chain.plugin('private/build-manifest').tap(([options]) => [
|
|
36
|
-
Object.assign(Object.assign({}, options), { modules: false })
|
|
37
|
-
]);
|
|
38
35
|
chain.plugin('define').tap(([options]) => [
|
|
39
36
|
Object.assign(Object.assign({}, options), { __BROWSER__: false })
|
|
40
37
|
]);
|
|
41
38
|
return (0, style_1.withStyle)(chain, {
|
|
42
39
|
ssr: true,
|
|
43
|
-
|
|
40
|
+
lightningCss: options.lightningCss,
|
|
44
41
|
filename: 'static/css/[contenthash:8].css',
|
|
45
42
|
chunkFilename: 'static/css/[contenthash:8].chunk.css'
|
|
46
43
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nodeExternals = void 0;
|
|
4
|
-
// import resolve from "resolve";
|
|
5
|
-
const constants_1 = require("../../../constants");
|
|
6
4
|
function match(value, tests) {
|
|
7
5
|
let matched = false;
|
|
8
6
|
for (let index = 0; index < tests.length; index++) {
|
|
@@ -31,17 +29,12 @@ function nodeExternals({ projectRoot, include }) {
|
|
|
31
29
|
return next(null, `commonjs ${request}`);
|
|
32
30
|
}
|
|
33
31
|
const notExternalModules = [];
|
|
34
|
-
const externalModules = [
|
|
35
|
-
/platform-shared[/\\](esm|lib)[/\\]shared[/\\]shuvi-singleton-runtimeConfig/
|
|
36
|
-
];
|
|
32
|
+
const externalModules = [];
|
|
37
33
|
// make sure we don't externalize anything that is
|
|
38
34
|
// supposed to be transpiled
|
|
39
35
|
if (match(request, include)) {
|
|
40
36
|
return transpiled();
|
|
41
37
|
}
|
|
42
|
-
if (match(request, constants_1.AppSourceRegexs)) {
|
|
43
|
-
return transpiled();
|
|
44
|
-
}
|
|
45
38
|
if (match(request, notExternalModules)) {
|
|
46
39
|
return transpiled();
|
|
47
40
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { IWebpackHelpers } from '../../types';
|
|
2
2
|
export declare const webpackHelpers: () => IWebpackHelpers;
|
|
3
3
|
export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
|
|
4
|
+
export declare function splitChunksFilter(chunk: any): boolean;
|
|
5
|
+
export declare const commonChunkFilename: ({ dev }: {
|
|
6
|
+
dev: boolean;
|
|
7
|
+
}) => string;
|
|
@@ -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.commonChunkFilename = 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,14 @@ 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;
|
|
58
|
+
const commonChunkFilename = ({ dev }) => {
|
|
59
|
+
return `static/common/${dev ? '[name]' : '[name].[contenthash:8]'}.js`;
|
|
60
|
+
};
|
|
61
|
+
exports.commonChunkFilename = commonChunkFilename;
|
|
@@ -6,7 +6,7 @@ interface StyleOptions {
|
|
|
6
6
|
extractCss?: boolean;
|
|
7
7
|
sourceMap?: boolean;
|
|
8
8
|
ssr?: boolean;
|
|
9
|
-
|
|
9
|
+
lightningCss?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath,
|
|
11
|
+
export declare function withStyle(chain: Config, { extractCss, sourceMap, ssr, publicPath, lightningCss, filename, chunkFilename }: StyleOptions): Config;
|
|
12
12
|
export {};
|