@shuvi/toolpack 1.0.0-rc.9 → 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 +35 -35
- package/lib/webpack/config/browser.js +45 -23
- 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 +3 -0
- package/lib/webpack/config/parts/helpers.js +6 -2
- 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 -2
- package/lib/constants.js +0 -7
- 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,9 +34,7 @@ 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
37
|
const fix_watching_plugin_1 = __importDefault(require("../plugins/fix-watching-plugin"));
|
|
39
|
-
const constants_2 = require("../../constants");
|
|
40
38
|
const crypto = __importStar(require("crypto"));
|
|
41
39
|
const jsconfig_paths_plugin_1 = __importDefault(require("../plugins/jsconfig-paths-plugin"));
|
|
42
40
|
const support_ts_extension_resolver_plugin_1 = __importDefault(require("../plugins/support-ts-extension-resolver-plugin"));
|
|
@@ -61,7 +59,21 @@ 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');
|
|
@@ -71,11 +83,11 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
71
83
|
config.output.path(outputDir);
|
|
72
84
|
config.output.merge({
|
|
73
85
|
publicPath,
|
|
74
|
-
filename: `${dev ? '[name]
|
|
86
|
+
filename: `${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
75
87
|
// This saves chunks with the name given via `import()`
|
|
76
88
|
chunkFilename: `static/chunks/${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
|
|
77
89
|
hotUpdateChunkFilename: 'static/webpack/[id].[fullhash].hot-update.js',
|
|
78
|
-
hotUpdateMainFilename: 'static/webpack/[fullhash].hot-update.json',
|
|
90
|
+
hotUpdateMainFilename: 'static/webpack/[runtime].[fullhash].hot-update.json',
|
|
79
91
|
strictModuleExceptionHandling: true,
|
|
80
92
|
// crossOriginLoading: crossOrigin,
|
|
81
93
|
webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
|
|
@@ -99,7 +111,7 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
99
111
|
default: false,
|
|
100
112
|
vendors: {
|
|
101
113
|
name: 'vendors',
|
|
102
|
-
filename:
|
|
114
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: true }),
|
|
103
115
|
test: /[\\/]node_modules[\\/]/,
|
|
104
116
|
// Don't let webpack eliminate this chunk (prevents this chunk from
|
|
105
117
|
// becoming a part of the commons chunk)
|
|
@@ -120,8 +132,8 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
120
132
|
config.optimization.minimizer('cssMinimizer').use(css_minimizer_webpack_plugin_1.default, [
|
|
121
133
|
{
|
|
122
134
|
// @ts-ignore
|
|
123
|
-
minify:
|
|
124
|
-
? css_minimizer_webpack_plugin_1.default.
|
|
135
|
+
minify: lightningCss
|
|
136
|
+
? css_minimizer_webpack_plugin_1.default.lightningCssMinify
|
|
125
137
|
: css_minimizer_webpack_plugin_1.default.cssnanoMinify
|
|
126
138
|
}
|
|
127
139
|
]);
|
|
@@ -134,14 +146,14 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
134
146
|
modules: [
|
|
135
147
|
'node_modules',
|
|
136
148
|
...nodePathList // Support for NODE_PATH environment variable
|
|
137
|
-
]
|
|
138
|
-
alias: {}
|
|
149
|
+
]
|
|
139
150
|
});
|
|
151
|
+
config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
|
|
140
152
|
config.resolveLoader.merge({
|
|
141
153
|
alias: [
|
|
154
|
+
'lightningcss-loader',
|
|
142
155
|
'shuvi-swc-loader',
|
|
143
|
-
'route-component-loader'
|
|
144
|
-
'parcel-css-loader'
|
|
156
|
+
'route-component-loader'
|
|
145
157
|
].reduce((alias, loader) => {
|
|
146
158
|
alias[`@shuvi/${loader}`] = resolveLocalLoader(loader);
|
|
147
159
|
return alias;
|
|
@@ -158,18 +170,16 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
158
170
|
mainRule
|
|
159
171
|
.oneOf('js')
|
|
160
172
|
.test(/\.(tsx|ts|js|cjs|mjs|jsx)$/)
|
|
161
|
-
.include.merge([...include
|
|
173
|
+
.include.merge([...include])
|
|
162
174
|
.end()
|
|
163
175
|
.use('shuvi-swc-loader')
|
|
164
176
|
.loader('@shuvi/shuvi-swc-loader')
|
|
165
177
|
.options({
|
|
166
178
|
isServer: false,
|
|
167
|
-
experimental,
|
|
168
179
|
compiler,
|
|
169
180
|
supportedBrowsers: false,
|
|
170
181
|
swcCacheDir: path.join(cacheDir, 'swc')
|
|
171
182
|
});
|
|
172
|
-
config.resolve.alias.set('@swc/helpers', path.dirname(require.resolve(`@swc/helpers/package.json`)));
|
|
173
183
|
mainRule
|
|
174
184
|
.oneOf('media')
|
|
175
185
|
.exclude.merge([/\.(tsx|ts|js|cjs|mjs|jsx)$/, /\.html$/, /\.json$/])
|
|
@@ -185,32 +195,22 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
|
|
|
185
195
|
contextRegExp: /moment$/
|
|
186
196
|
}
|
|
187
197
|
]);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return prev;
|
|
193
|
-
}, {});
|
|
194
|
-
const shuviConfigEnv = Object.keys(env).reduce((acc, key) => {
|
|
195
|
-
if (/^(?:NODE_.+)|^(?:__.+)$/i.test(key)) {
|
|
196
|
-
throw new Error(`The key "${key}" under "env" is not allowed.`);
|
|
197
|
-
}
|
|
198
|
-
return Object.assign(Object.assign({}, acc), { [`process.env.${key}`]: JSON.stringify(env[key]) });
|
|
199
|
-
}, {});
|
|
200
|
-
config.plugin('define').use(webpack_1.default.DefinePlugin, [
|
|
201
|
-
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))
|
|
202
202
|
]);
|
|
203
|
-
config
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
config.plugin('define').use(webpack_1.default.DefinePlugin, [
|
|
204
|
+
{
|
|
205
|
+
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production')
|
|
206
|
+
}
|
|
207
207
|
]);
|
|
208
208
|
const getCacheConfig = () => {
|
|
209
209
|
const projectHash = crypto
|
|
210
210
|
.createHash('md5')
|
|
211
211
|
.update(projectRoot)
|
|
212
212
|
.digest('hex');
|
|
213
|
-
const stringifiedEnvs = Object.entries(Object.assign(
|
|
213
|
+
const stringifiedEnvs = Object.entries(Object.assign({}, getDefineEnv(env))).reduce((prev, [key, value]) => {
|
|
214
214
|
return `${prev}|${key}=${value}`;
|
|
215
215
|
}, '');
|
|
216
216
|
const PACKAGE_JSON = path.resolve(__dirname, '../../../package.json');
|
|
@@ -32,13 +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
|
-
// import PreferResolverPlugin from '../plugins/prefer-resolver-plugin';
|
|
36
|
-
const constants_1 = require("../../constants");
|
|
37
|
-
const dynamic_public_path_plugin_1 = __importDefault(require("../plugins/dynamic-public-path-plugin"));
|
|
38
35
|
const base_1 = require("./base");
|
|
39
36
|
const style_1 = require("./parts/style");
|
|
40
37
|
const helpers_1 = require("./parts/helpers");
|
|
41
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
|
+
];
|
|
42
52
|
function createBrowserWebpackChain(options) {
|
|
43
53
|
const { cacheDir, typescript, dev, publicPath, analyze } = options;
|
|
44
54
|
const chain = (0, base_1.baseWebpackChain)(options);
|
|
@@ -82,11 +92,6 @@ function createBrowserWebpackChain(options) {
|
|
|
82
92
|
}
|
|
83
93
|
]);
|
|
84
94
|
}
|
|
85
|
-
// if (options.target) {
|
|
86
|
-
// chain.resolve
|
|
87
|
-
// .plugin('private/prefer-resolver-plugin')
|
|
88
|
-
// .use(PreferResolverPlugin, [{ suffix: options.target }]);
|
|
89
|
-
// }
|
|
90
95
|
if (dev) {
|
|
91
96
|
chain.plugin('private/hmr-plugin').use(webpack_1.default.HotModuleReplacementPlugin);
|
|
92
97
|
}
|
|
@@ -99,15 +104,36 @@ function createBrowserWebpackChain(options) {
|
|
|
99
104
|
framework: {
|
|
100
105
|
chunks: 'all',
|
|
101
106
|
name: 'framework',
|
|
102
|
-
filename:
|
|
103
|
-
|
|
104
|
-
// bundled with their issuer.
|
|
105
|
-
// https://github.com/zeit/next.js/pull/9012
|
|
106
|
-
test(module) {
|
|
107
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
|
|
108
|
+
test(module, { moduleGraph }) {
|
|
107
109
|
const resource = module.nameForCondition();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
});
|
|
111
137
|
},
|
|
112
138
|
// test: /(?<!node_modules.*)[\\/]node_modules[\\/](react|react-dom|@shuvi[\\/]router|@shuvi[\\/]router-react|scheduler|prop-types|use-sync-external-store|history)[\\/]/,
|
|
113
139
|
priority: 40,
|
|
@@ -118,7 +144,7 @@ function createBrowserWebpackChain(options) {
|
|
|
118
144
|
lib: {
|
|
119
145
|
test(module) {
|
|
120
146
|
return (module.size() > BIG_LIBRARY_THRESHOLD &&
|
|
121
|
-
/node_modules[/\\]/.test(module.nameForCondition() || ''));
|
|
147
|
+
/[/\\]node_modules[/\\]/.test(module.nameForCondition() || ''));
|
|
122
148
|
},
|
|
123
149
|
name(module) {
|
|
124
150
|
const hash = crypto.createHash('sha1');
|
|
@@ -133,7 +159,7 @@ function createBrowserWebpackChain(options) {
|
|
|
133
159
|
}
|
|
134
160
|
return hash.digest('hex').substring(0, 8);
|
|
135
161
|
},
|
|
136
|
-
filename:
|
|
162
|
+
filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
|
|
137
163
|
priority: 30,
|
|
138
164
|
minChunks: 1,
|
|
139
165
|
reuseExistingChunk: true
|
|
@@ -178,14 +204,10 @@ function createBrowserWebpackChain(options) {
|
|
|
178
204
|
// prevent errof of destructing process.env
|
|
179
205
|
'process.env': JSON.stringify('{}') })
|
|
180
206
|
]);
|
|
181
|
-
chain.plugin('dynamic-public-path-plugin').use(dynamic_public_path_plugin_1.default);
|
|
182
|
-
chain.plugin('private/build-manifest').tap(([options]) => [
|
|
183
|
-
Object.assign(Object.assign({}, options), { modules: true })
|
|
184
|
-
]);
|
|
185
207
|
return (0, style_1.withStyle)(chain, {
|
|
186
208
|
extractCss: !dev,
|
|
187
209
|
publicPath,
|
|
188
|
-
|
|
210
|
+
lightningCss: options.lightningCss,
|
|
189
211
|
filename: 'static/css/[contenthash:8].css',
|
|
190
212
|
chunkFilename: 'static/css/[contenthash:8].chunk.css'
|
|
191
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
|
}
|
|
@@ -2,3 +2,6 @@ import { IWebpackHelpers } from '../../types';
|
|
|
2
2
|
export declare const webpackHelpers: () => IWebpackHelpers;
|
|
3
3
|
export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
|
|
4
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.splitChunksFilter = 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) => {
|
|
@@ -50,8 +50,12 @@ function shouldUseRelativeAssetPaths(publicPath) {
|
|
|
50
50
|
exports.shouldUseRelativeAssetPaths = shouldUseRelativeAssetPaths;
|
|
51
51
|
function splitChunksFilter(chunk) {
|
|
52
52
|
const excludes = {
|
|
53
|
-
|
|
53
|
+
// 'static/polyfill': true
|
|
54
54
|
};
|
|
55
55
|
return excludes[chunk.name] !== true;
|
|
56
56
|
}
|
|
57
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 {};
|
|
@@ -33,39 +33,48 @@ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plug
|
|
|
33
33
|
const loaderUtils = __importStar(require("loader-utils"));
|
|
34
34
|
const path = __importStar(require("path"));
|
|
35
35
|
const helpers_1 = require("./helpers");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
36
|
+
const regexLikeIndexModule = /(?<!pages[\\/])index\.(scss|sass|css)$/;
|
|
37
|
+
function getCSSModuleLocalIdent(context, _, exportName, options) {
|
|
38
|
+
const relativePath = path
|
|
39
|
+
.relative(context.rootContext, context.resourcePath)
|
|
40
|
+
.replace(/\\+/g, '/');
|
|
41
|
+
// Generate a more meaningful name (parent folder) when the user names the
|
|
42
|
+
// file `index.css`.
|
|
43
|
+
const fileNameOrFolder = regexLikeIndexModule.test(relativePath)
|
|
39
44
|
? '[folder]'
|
|
40
45
|
: '[name]';
|
|
41
|
-
//
|
|
42
|
-
const hash = loaderUtils.getHashDigest(
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// Generate a hash to make the class name unique.
|
|
47
|
+
const hash = loaderUtils.getHashDigest(Buffer.from(`filePath:${relativePath}#className:${exportName}`), 'md5', 'base64', 5);
|
|
48
|
+
// Have webpack interpolate the `[folder]` or `[name]` to its real value.
|
|
49
|
+
return (loaderUtils
|
|
50
|
+
.interpolateName(context, fileNameOrFolder + '_' + exportName + '__' + hash, options)
|
|
51
|
+
// Replace invalid symbols with underscores instead of escaping
|
|
52
|
+
// https://mathiasbynens.be/notes/css-escapes#identifiers-strings
|
|
53
|
+
.replace(/[^a-zA-Z0-9-_]/g, '_')
|
|
54
|
+
// "they cannot start with a digit, two hyphens, or a hyphen followed by a digit [sic]"
|
|
55
|
+
// https://www.w3.org/TR/CSS21/syndata.html#characters
|
|
56
|
+
.replace(/^(\d|--|-\d)/, '__$1'));
|
|
49
57
|
}
|
|
50
58
|
// style files regexes
|
|
51
59
|
const cssRegex = /\.css$/;
|
|
52
60
|
const cssModuleQueryRegex = /cssmodules/;
|
|
53
61
|
const sassRegex = /\.(scss|sass)$/;
|
|
54
|
-
function ssrCssRule({ test, resourceQuery, scss,
|
|
62
|
+
function ssrCssRule({ test, resourceQuery, scss, lightningCss }) {
|
|
55
63
|
const rule = new Rule_1.default();
|
|
56
64
|
rule.test(test);
|
|
57
65
|
if (resourceQuery) {
|
|
58
66
|
rule.resourceQuery(resourceQuery);
|
|
59
67
|
}
|
|
60
|
-
if (
|
|
68
|
+
if (lightningCss) {
|
|
61
69
|
rule
|
|
62
|
-
.use('
|
|
63
|
-
.loader('@shuvi/
|
|
70
|
+
.use('lightningcss-loader')
|
|
71
|
+
.loader('@shuvi/lightningcss-loader')
|
|
64
72
|
.options({
|
|
65
73
|
sourceMap: false,
|
|
66
74
|
importLoaders: scss ? 1 : 0,
|
|
67
75
|
esModule: true,
|
|
68
76
|
modules: {
|
|
77
|
+
getLocalIdent: () => '[name]_[local]__[hash]',
|
|
69
78
|
exportOnlyLocals: true
|
|
70
79
|
}
|
|
71
80
|
});
|
|
@@ -97,7 +106,7 @@ function ssrCssRule({ test, resourceQuery, scss, parcelCss }) {
|
|
|
97
106
|
}
|
|
98
107
|
return rule;
|
|
99
108
|
}
|
|
100
|
-
function cssRule({ publicPath, test, resourceQuery, cssModule,
|
|
109
|
+
function cssRule({ publicPath, test, resourceQuery, cssModule, lightningCss, extractCss, sourceMap, scss }) {
|
|
101
110
|
const rule = new Rule_1.default();
|
|
102
111
|
rule.test(test);
|
|
103
112
|
if (resourceQuery) {
|
|
@@ -134,22 +143,19 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
|
|
|
134
143
|
// anchor. By inserting before and not after, we do not
|
|
135
144
|
// need to track the last inserted element.
|
|
136
145
|
parentNode.insertBefore(element, anchorElement);
|
|
137
|
-
|
|
138
|
-
window["${constants_1.DEV_STYLE_PREPARE}"] = new Promise(function(resolve) {
|
|
139
|
-
(window.requestAnimationFrame || setTimeout)(function() {
|
|
140
|
-
resolve();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
146
|
`),
|
|
144
147
|
esModule: true
|
|
145
148
|
});
|
|
146
149
|
}
|
|
147
|
-
if (
|
|
150
|
+
if (lightningCss) {
|
|
148
151
|
rule
|
|
149
|
-
.use('
|
|
150
|
-
.loader('@shuvi/
|
|
152
|
+
.use('lightningcss-loader')
|
|
153
|
+
.loader('@shuvi/lightningcss-loader')
|
|
151
154
|
.options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
|
|
152
|
-
modules: {
|
|
155
|
+
modules: {
|
|
156
|
+
getLocalIdent: () => '[name]_[local]__[hash]',
|
|
157
|
+
exportOnlyLocals: false
|
|
158
|
+
}
|
|
153
159
|
})));
|
|
154
160
|
}
|
|
155
161
|
else {
|
|
@@ -158,8 +164,8 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
|
|
|
158
164
|
.loader(require.resolve('css-loader'))
|
|
159
165
|
.options(Object.assign({ sourceMap, importLoaders: scss ? 2 : 1, esModule: true }, (cssModule && {
|
|
160
166
|
modules: {
|
|
161
|
-
getLocalIdent: getCSSModuleLocalIdent
|
|
162
|
-
|
|
167
|
+
getLocalIdent: getCSSModuleLocalIdent,
|
|
168
|
+
exportOnlyLocals: false
|
|
163
169
|
}
|
|
164
170
|
})));
|
|
165
171
|
rule
|
|
@@ -195,7 +201,7 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, parcelCss, extrac
|
|
|
195
201
|
}
|
|
196
202
|
return rule;
|
|
197
203
|
}
|
|
198
|
-
function withStyle(chain, { extractCss, sourceMap, ssr, publicPath,
|
|
204
|
+
function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, lightningCss, filename, chunkFilename }) {
|
|
199
205
|
const oneOfs = chain.module.rule('main').oneOfs;
|
|
200
206
|
if (ssr) {
|
|
201
207
|
oneOfs.set('css-module',
|
|
@@ -204,7 +210,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
204
210
|
test: cssRegex,
|
|
205
211
|
resourceQuery: cssModuleQueryRegex,
|
|
206
212
|
scss: false,
|
|
207
|
-
|
|
213
|
+
lightningCss
|
|
208
214
|
}).after('js'));
|
|
209
215
|
oneOfs.set('scss-module',
|
|
210
216
|
// @ts-ignore
|
|
@@ -212,8 +218,9 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
212
218
|
test: sassRegex,
|
|
213
219
|
resourceQuery: cssModuleQueryRegex,
|
|
214
220
|
scss: true,
|
|
215
|
-
|
|
221
|
+
lightningCss
|
|
216
222
|
}).after('css-module'));
|
|
223
|
+
// ignore noraml css module
|
|
217
224
|
const ignoreRule = new Rule_1.default();
|
|
218
225
|
ignoreRule
|
|
219
226
|
.test([cssRegex, sassRegex])
|
|
@@ -239,7 +246,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
239
246
|
test: cssRegex,
|
|
240
247
|
resourceQuery: cssModuleQueryRegex,
|
|
241
248
|
cssModule: true,
|
|
242
|
-
|
|
249
|
+
lightningCss,
|
|
243
250
|
scss: false,
|
|
244
251
|
extractCss,
|
|
245
252
|
sourceMap,
|
|
@@ -250,7 +257,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
250
257
|
cssRule({
|
|
251
258
|
test: cssRegex,
|
|
252
259
|
cssModule: false,
|
|
253
|
-
|
|
260
|
+
lightningCss,
|
|
254
261
|
scss: false,
|
|
255
262
|
extractCss,
|
|
256
263
|
sourceMap,
|
|
@@ -262,7 +269,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
262
269
|
test: sassRegex,
|
|
263
270
|
resourceQuery: cssModuleQueryRegex,
|
|
264
271
|
cssModule: true,
|
|
265
|
-
|
|
272
|
+
lightningCss,
|
|
266
273
|
scss: true,
|
|
267
274
|
extractCss,
|
|
268
275
|
sourceMap,
|
|
@@ -273,7 +280,7 @@ function withStyle(chain, { extractCss, sourceMap, ssr, publicPath, parcelCss, f
|
|
|
273
280
|
cssRule({
|
|
274
281
|
test: sassRegex,
|
|
275
282
|
cssModule: false,
|
|
276
|
-
|
|
283
|
+
lightningCss,
|
|
277
284
|
scss: true,
|
|
278
285
|
extractCss,
|
|
279
286
|
sourceMap,
|
package/lib/webpack/index.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export { webpack as default };
|
|
3
|
-
export { WebpackChain } from './config';
|
|
4
|
-
export { DynamicDll } from './dynamic-dll';
|
|
1
|
+
export * from './webpack';
|
|
5
2
|
/**
|
|
6
|
-
*
|
|
3
|
+
* resolve webpack sub module from the same webpack module
|
|
7
4
|
*/
|
|
8
|
-
export
|
|
9
|
-
/** export */
|
|
10
|
-
AutomaticPrefetchPlugin, AsyncDependenciesBlock, BannerPlugin, Cache, Chunk, ChunkGraph, CleanPlugin, Compilation, Compiler, ConcatenationScope, ContextExclusionPlugin, ContextReplacementPlugin, DefinePlugin, DelegatedPlugin, Dependency, DllPlugin, DllReferencePlugin, DynamicEntryPlugin, EntryOptionPlugin, EntryPlugin, EnvironmentPlugin, EvalDevToolModulePlugin, EvalSourceMapDevToolPlugin, ExternalModule, ExternalsPlugin, Generator, HotUpdateChunk, HotModuleReplacementPlugin, IgnorePlugin, JavascriptModulesPlugin, LibManifestPlugin, LibraryTemplatePlugin, LoaderOptionsPlugin, LoaderTargetPlugin, Module, ModuleGraph, ModuleGraphConnection, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, MultiCompiler, Parser, Plugin, PrefetchPlugin, ProgressPlugin, ProvidePlugin, RuntimeModule, EntryPlugin as SingleEntryPlugin, SourceMapDevToolPlugin, Stats, Template, WatchIgnorePlugin, WebpackError, WebpackOptionsApply, WebpackOptionsDefaulter, Entry, EntryNormalized, EntryObject, LibraryOptions, ModuleOptions, ResolveOptions, RuleSetCondition, RuleSetConditionAbsolute, RuleSetRule, RuleSetUse, RuleSetUseItem, Configuration, WebpackOptionsNormalized, WebpackPluginInstance, Asset, AssetInfo, MultiStats, ParserState, Watching, StatsAsset, StatsChunk, StatsChunkGroup, StatsChunkOrigin, StatsCompilation, StatsError, StatsLogging, StatsLoggingEntry, StatsModule, StatsModuleIssuer, StatsModuleReason, StatsModuleTraceDependency, StatsModuleTraceItem, StatsProfile } from 'webpack';
|
|
11
|
-
/**
|
|
12
|
-
* resolve webpack module for not shuvi plugin
|
|
13
|
-
*/
|
|
14
|
-
declare const webpackResolveContext: string;
|
|
15
|
-
export { webpackResolveContext };
|
|
5
|
+
export declare function resolveWebpackModule(path: string): any;
|