@umijs/bundler-webpack 4.0.0-beta.12 → 4.0.0-beta.16
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/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
- package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +49 -0
- package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
- package/compiled/webpack-manifest-plugin/LICENSE +21 -0
- package/compiled/webpack-manifest-plugin/index.js +1 -0
- package/compiled/webpack-manifest-plugin/package.json +1 -0
- package/dist/build.d.ts +3 -2
- package/dist/build.js +1 -0
- package/dist/config/config.d.ts +6 -2
- package/dist/config/config.js +44 -4
- package/dist/config/cssRules.js +1 -1
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +34 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
- package/dist/config/javaScriptRules.js +2 -19
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +25 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
- package/dist/config/miniCSSExtractPlugin.js +2 -3
- package/dist/dev.d.ts +3 -2
- package/dist/dev.js +17 -5
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +54 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
- package/dist/schema.js +7 -5
- package/dist/server/server.js +20 -1
- package/dist/types.d.ts +6 -0
- package/package.json +13 -8
- package/compiled/swc-loader/LICENSE +0 -25
- package/compiled/swc-loader/index.js +0 -1
- package/compiled/swc-loader/package.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"fork-ts-checker-webpack-plugin","author":"Piotr Oleś <piotrek.oles@gmail.com>","license":"MIT","types":"lib/index.d.ts"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Dane Thurber <dane.thurber@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";var e={927:function(e,t,s){Object.defineProperty(t,"__esModule",{value:true});t.transformFiles=t.reduceChunk=t.reduceAssets=t.generateManifest=void 0;const n=s(17);const generateManifest=(e,t,{generate:s,seed:n={}})=>{let o;if(s){const i=Array.from(e.entrypoints.entries());const a=i.reduce(((e,[t,s])=>Object.assign(e,{[t]:s.getFiles()})),{});o=s(n,t,a)}else{o=t.reduce(((e,t)=>Object.assign(e,{[t.name]:t.path})),n)}return o};t.generateManifest=generateManifest;const getFileType=(e,{transformExtensions:t})=>{const s=e.replace(/\?.*/,"");const n=s.split(".");const o=n.pop();return t.test(o)?`${n.pop()}.${o}`:o};const reduceAssets=(e,t,s)=>{let o;if(s[t.name]){o=s[t.name]}else if(t.info.sourceFilename){o=n.join(n.dirname(t.name),n.basename(t.info.sourceFilename))}if(o){return e.concat({isAsset:true,isChunk:false,isInitial:false,isModuleAsset:true,name:o,path:t.name})}const i=t.chunks&&t.chunks.length>0;if(i){return e}return e.concat({isAsset:true,isChunk:false,isInitial:false,isModuleAsset:false,name:t.name,path:t.name})};t.reduceAssets=reduceAssets;const reduceChunk=(e,t,s,o)=>{Array.from(t.auxiliaryFiles||[]).forEach((e=>{o[e]={isAsset:true,isChunk:false,isInitial:false,isModuleAsset:true,name:n.basename(e),path:e}}));return Array.from(t.files).reduce(((e,n)=>{let o=t.name?t.name:null;o=o?s.useEntryKeys&&!n.endsWith(".map")?o:`${o}.${getFileType(n,s)}`:n;return e.concat({chunk:t,isAsset:false,isChunk:true,isInitial:t.isOnlyInitial(),isModuleAsset:false,name:o,path:n})}),e)};t.reduceChunk=reduceChunk;const standardizeFilePaths=e=>{const t=Object.assign({},e);t.name=e.name.replace(/\\/g,"/");t.path=e.path.replace(/\\/g,"/");return t};const transformFiles=(e,t)=>["filter","map","sort"].filter((e=>!!t[e])).reduce(((e,s)=>e[s](t[s])),e).map(standardizeFilePaths);t.transformFiles=transformFiles},961:function(e,t,s){Object.defineProperty(t,"__esModule",{value:true});t.normalModuleLoaderHook=t.getCompilerHooks=t.emitHook=t.beforeRunHook=void 0;const n=s(147);const o=s(17);const i=s(535);const a=s(728);const r=s(927);const u=new WeakMap;const getCompilerHooks=e=>{let t=u.get(e);if(typeof t==="undefined"){t={afterEmit:new i.SyncWaterfallHook(["manifest"]),beforeEmit:new i.SyncWaterfallHook(["manifest"])};u.set(e,t)}return t};t.getCompilerHooks=getCompilerHooks;const beforeRunHook=({emitCountMap:e,manifestFileName:t},s,n)=>{const o=e.get(t)||0;e.set(t,o+1);if(n){n()}};t.beforeRunHook=beforeRunHook;const l=function emit({compiler:e,emitCountMap:t,manifestAssetId:s,manifestFileName:i,moduleAssets:u,options:l},c){const p=t.get(i)-1;const m=c.getStats().toJson({all:false,assets:true,cachedAssets:true,ids:true,publicPath:true});const f=l.publicPath!==null?l.publicPath:m.publicPath;const{basePath:d,removeKeyHash:h}=l;t.set(i,p);const k={};let b=Array.from(c.chunks).reduce(((e,t)=>r.reduceChunk(e,t,l,k)),[]);b=m.assets.reduce(((e,t)=>r.reduceAssets(e,t,u)),b);b=b.filter((({name:s,path:n})=>{var i;return!n.includes("hot-update")&&typeof t.get(o.join(((i=e.options.output)===null||i===void 0?void 0:i.path)||"<unknown>",s))==="undefined"}));b.forEach((e=>{delete k[e.path]}));Object.keys(k).forEach((e=>{b=b.concat(k[e])}));b=b.map((e=>{const t={name:d?d+e.name:e.name,path:f?f+e.path:e.path};t.name=h?t.name.replace(h,""):t.name;return Object.assign(e,t)}));b=r.transformFiles(b,l);let g=r.generateManifest(c,b,l);const _=p===0;g=getCompilerHooks(e).beforeEmit.call(g);if(_){const e=l.serialize(g);c.emitAsset(s,new a.RawSource(e));if(l.writeToFileEmit){n.mkdirSync(o.dirname(i),{recursive:true});n.writeFileSync(i,e)}}getCompilerHooks(e).afterEmit.call(g)};t.emitHook=l;const normalModuleLoaderHook=({moduleAssets:e},t,s)=>{const{emitFile:n}=t;t.emitFile=(t,i,a)=>{if(s.userRequest&&!e[t]){Object.assign(e,{[t]:o.join(o.dirname(t),o.basename(s.userRequest))})}return n.call(s,t,i,a)}};t.normalModuleLoaderHook=normalModuleLoaderHook},871:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.WebpackManifestPlugin=t.getCompilerHooks=void 0;const o=s(17);const i=n(s(27));const a=n(s(205));const r=s(961);Object.defineProperty(t,"getCompilerHooks",{enumerable:true,get:function(){return r.getCompilerHooks}});const u=new Map;const l={basePath:"",fileName:"manifest.json",filter:null,generate:void 0,map:null,publicPath:null,removeKeyHash:/([a-f0-9]{16,32}\.?)/gi,seed:void 0,serialize(e){return JSON.stringify(e,null,2)},sort:null,transformExtensions:/^(gz|map)$/i,useEntryKeys:false,useLegacyEmit:false,writeToFileEmit:false};class WebpackManifestPlugin{constructor(e){this.options=Object.assign({},l,e)}apply(e){var t,s,n;const l={};const c=o.resolve(((t=e.options.output)===null||t===void 0?void 0:t.path)||"./",this.options.fileName);const p=o.relative(((s=e.options.output)===null||s===void 0?void 0:s.path)||"./",c);const m=r.beforeRunHook.bind(this,{emitCountMap:u,manifestFileName:c});const f=r.emitHook.bind(this,{compiler:e,emitCountMap:u,manifestAssetId:p,manifestFileName:c,moduleAssets:l,options:this.options});const d=r.normalModuleLoaderHook.bind(this,{moduleAssets:l});const h={name:"WebpackManifestPlugin",stage:Infinity};e.hooks.compilation.tap(h,(e=>{const t=!a.default.getCompilationHooks?e.hooks.normalModuleLoader:a.default.getCompilationHooks(e).loader;t.tap(h,d)}));if(((n=i.default.version)===null||n===void 0?void 0:n.startsWith("4"))||this.options.useLegacyEmit===true){e.hooks.emit.tap(h,f)}else{e.hooks.thisCompilation.tap(h,(e=>{e.hooks.processAssets.tap(h,(()=>f(e)))}))}e.hooks.run.tap(h,m);e.hooks.watchRun.tap(h,m)}}t.WebpackManifestPlugin=WebpackManifestPlugin},205:function(e){e.exports=require("../webpack/NormalModule")},535:function(e){e.exports=require("@umijs/bundler-webpack/compiled/tapable")},27:function(e){e.exports=require("@umijs/bundler-webpack/compiled/webpack")},728:function(e){e.exports=require("@umijs/bundler-webpack/compiled/webpack-sources")},147:function(e){e.exports=require("fs")},17:function(e){e.exports=require("path")}};var t={};function __nccwpck_require__(s){var n=t[s];if(n!==undefined){return n.exports}var o=t[s]={exports:{}};var i=true;try{e[s].call(o.exports,o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete t[s]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s=__nccwpck_require__(871);module.exports=s})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"webpack-manifest-plugin","author":"Dane Thurber <dane.thurber@gmail.com>","license":"MIT"}
|
package/dist/build.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { IOpts as IConfigOpts } from './config/config';
|
|
1
2
|
import { IConfig } from './types';
|
|
2
|
-
|
|
3
|
+
declare type IOpts = {
|
|
3
4
|
cwd: string;
|
|
4
5
|
entry: Record<string, string>;
|
|
5
6
|
config: IConfig;
|
|
@@ -12,6 +13,6 @@ interface IOpts {
|
|
|
12
13
|
extraBabelPlugins?: any[];
|
|
13
14
|
extraBabelPresets?: any[];
|
|
14
15
|
clean?: boolean;
|
|
15
|
-
}
|
|
16
|
+
} & Pick<IConfigOpts, 'cache'>;
|
|
16
17
|
export declare function build(opts: IOpts): Promise<void>;
|
|
17
18
|
export {};
|
package/dist/build.js
CHANGED
package/dist/config/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Configuration } from '../../compiled/webpack';
|
|
2
2
|
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
3
|
+
export interface IOpts {
|
|
4
4
|
cwd: string;
|
|
5
5
|
env: Env;
|
|
6
6
|
entry: Record<string, string>;
|
|
@@ -15,6 +15,10 @@ interface IOpts {
|
|
|
15
15
|
userConfig: IConfig;
|
|
16
16
|
analyze?: any;
|
|
17
17
|
name?: string;
|
|
18
|
+
cache?: {
|
|
19
|
+
absNodeModulesPath?: string;
|
|
20
|
+
buildDependencies?: string[];
|
|
21
|
+
cacheDirectory?: string;
|
|
22
|
+
};
|
|
18
23
|
}
|
|
19
24
|
export declare function getConfig(opts: IOpts): Promise<Configuration>;
|
|
20
|
-
export {};
|
package/dist/config/config.js
CHANGED
|
@@ -17,6 +17,7 @@ const path_1 = require("path");
|
|
|
17
17
|
const webpack_1 = __importDefault(require("../../compiled/webpack"));
|
|
18
18
|
const webpack_5_chain_1 = __importDefault(require("../../compiled/webpack-5-chain"));
|
|
19
19
|
const constants_1 = require("../constants");
|
|
20
|
+
const RuntimePublicPathPlugin_1 = require("../plugins/RuntimePublicPathPlugin");
|
|
20
21
|
const types_1 = require("../types");
|
|
21
22
|
const browsersList_1 = require("../utils/browsersList");
|
|
22
23
|
const assetRules_1 = require("./assetRules");
|
|
@@ -26,8 +27,11 @@ const copyPlugin_1 = require("./copyPlugin");
|
|
|
26
27
|
const cssRules_1 = require("./cssRules");
|
|
27
28
|
const definePlugin_1 = require("./definePlugin");
|
|
28
29
|
const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
|
|
30
|
+
const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
|
|
31
|
+
const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
|
|
29
32
|
const ignorePlugin_1 = require("./ignorePlugin");
|
|
30
33
|
const javaScriptRules_1 = require("./javaScriptRules");
|
|
34
|
+
const manifestPlugin_1 = require("./manifestPlugin");
|
|
31
35
|
const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
|
|
32
36
|
const nodePolyfill_1 = require("./nodePolyfill");
|
|
33
37
|
const progressPlugin_1 = require("./progressPlugin");
|
|
@@ -41,6 +45,7 @@ function getConfig(opts) {
|
|
|
41
45
|
userConfig.targets = userConfig.targets || {
|
|
42
46
|
chrome: 80,
|
|
43
47
|
};
|
|
48
|
+
const useHash = !!(opts.hash || (userConfig.hash && !isDev));
|
|
44
49
|
const applyOpts = {
|
|
45
50
|
name: opts.name,
|
|
46
51
|
config,
|
|
@@ -53,6 +58,7 @@ function getConfig(opts) {
|
|
|
53
58
|
browsers: (0, browsersList_1.getBrowsersList)({
|
|
54
59
|
targets: userConfig.targets,
|
|
55
60
|
}),
|
|
61
|
+
useHash,
|
|
56
62
|
staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
|
|
57
63
|
};
|
|
58
64
|
// mode
|
|
@@ -61,7 +67,6 @@ function getConfig(opts) {
|
|
|
61
67
|
// entry
|
|
62
68
|
Object.keys(opts.entry).forEach((key) => {
|
|
63
69
|
const entry = config.entry(key);
|
|
64
|
-
// TODO: runtimePublicPath
|
|
65
70
|
if (isDev && opts.hmr) {
|
|
66
71
|
entry.add(require.resolve('../../client/client/client'));
|
|
67
72
|
}
|
|
@@ -75,7 +80,6 @@ function getConfig(opts) {
|
|
|
75
80
|
: userConfig.devtool);
|
|
76
81
|
// output
|
|
77
82
|
const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
|
|
78
|
-
const useHash = opts.hash || (userConfig.hash && !isDev);
|
|
79
83
|
const disableCompress = process.env.COMPRESS === 'none';
|
|
80
84
|
config.output
|
|
81
85
|
.path(absOutputPath)
|
|
@@ -131,10 +135,12 @@ function getConfig(opts) {
|
|
|
131
135
|
yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
|
|
132
136
|
// progress
|
|
133
137
|
yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
|
|
138
|
+
// fork-ts-checker
|
|
139
|
+
yield (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
|
|
134
140
|
// copy
|
|
135
141
|
yield (0, copyPlugin_1.addCopyPlugin)(applyOpts);
|
|
136
|
-
//
|
|
137
|
-
|
|
142
|
+
// manifest
|
|
143
|
+
yield (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
|
|
138
144
|
// hmr
|
|
139
145
|
if (isDev && opts.hmr) {
|
|
140
146
|
config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
|
|
@@ -143,6 +149,40 @@ function getConfig(opts) {
|
|
|
143
149
|
yield (0, compressPlugin_1.addCompressPlugin)(applyOpts);
|
|
144
150
|
// purgecss
|
|
145
151
|
// await applyPurgeCSSWebpackPlugin(applyOpts);
|
|
152
|
+
// handle HarmonyLinkingError
|
|
153
|
+
yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
154
|
+
// runtimePublicPath
|
|
155
|
+
if (userConfig.runtimePublicPath) {
|
|
156
|
+
config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
|
|
157
|
+
}
|
|
158
|
+
// cache
|
|
159
|
+
if (opts.cache) {
|
|
160
|
+
config.cache({
|
|
161
|
+
type: 'filesystem',
|
|
162
|
+
version: require('../../package.json').version,
|
|
163
|
+
buildDependencies: {
|
|
164
|
+
config: opts.cache.buildDependencies || [],
|
|
165
|
+
},
|
|
166
|
+
cacheDirectory: opts.cache.cacheDirectory ||
|
|
167
|
+
(0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'bundler-webpack'),
|
|
168
|
+
});
|
|
169
|
+
// tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
|
|
170
|
+
// 使用 immutablePaths 避免 node_modules 的内容被写入缓存
|
|
171
|
+
// tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
|
|
172
|
+
// ref: smallfish
|
|
173
|
+
if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
|
|
174
|
+
config.snapshot({
|
|
175
|
+
immutablePaths: [
|
|
176
|
+
opts.cache.absNodeModulesPath || (0, path_1.join)(opts.cwd, 'node_modules'),
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
config.infrastructureLogging(Object.assign({ level: 'error' }, (process.env.WEBPACK_FS_CACHE_DEBUG
|
|
181
|
+
? {
|
|
182
|
+
debug: /webpack\.cache/,
|
|
183
|
+
}
|
|
184
|
+
: {})));
|
|
185
|
+
}
|
|
146
186
|
// analyzer
|
|
147
187
|
if (opts.analyze) {
|
|
148
188
|
yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
|
package/dist/config/cssRules.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export declare function addForkTSCheckerPlugin(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.addForkTSCheckerPlugin = void 0;
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/fork-ts-checker-webpack-plugin"));
|
|
18
|
+
function addForkTSCheckerPlugin(opts) {
|
|
19
|
+
var _a;
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const { config, userConfig } = opts;
|
|
22
|
+
if (userConfig.forkTSChecker) {
|
|
23
|
+
// use user's typescript
|
|
24
|
+
if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
|
|
25
|
+
userConfig.forkTSChecker.typescript.typescriptPath =
|
|
26
|
+
require.resolve('typescript');
|
|
27
|
+
}
|
|
28
|
+
config
|
|
29
|
+
.plugin('fork-ts-checker-plugin')
|
|
30
|
+
.use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.addForkTSCheckerPlugin = addForkTSCheckerPlugin;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addHarmonyLinkingErrorPlugin = void 0;
|
|
13
|
+
// ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
|
|
14
|
+
const LINKING_ERROR_TAG = 'was not found in';
|
|
15
|
+
// build 时会出现 css modules 的引用警告,但这应该是需要忽略的
|
|
16
|
+
const CSS_NO_EXPORTS = /\.(css|sass|scss|styl|less)' \(module has no exports\)/;
|
|
17
|
+
class HarmonyLinkingErrorPlugin {
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
|
|
20
|
+
if (!compilation.warnings.length) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const harmonyLinkingErrors = compilation.warnings.filter((w) => {
|
|
24
|
+
return (w.name === 'ModuleDependencyWarning' &&
|
|
25
|
+
!w.module.resource.includes('node_modules') &&
|
|
26
|
+
w.message.includes(LINKING_ERROR_TAG) &&
|
|
27
|
+
!CSS_NO_EXPORTS.test(w.message));
|
|
28
|
+
});
|
|
29
|
+
if (!harmonyLinkingErrors.length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
compilation.errors.push(...harmonyLinkingErrors);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function addHarmonyLinkingErrorPlugin(opts) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { config } = opts;
|
|
39
|
+
config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
|
|
@@ -20,7 +20,7 @@ const types_1 = require("../types");
|
|
|
20
20
|
const depMatch_1 = require("../utils/depMatch");
|
|
21
21
|
function addJavaScriptRules(opts) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const { config, userConfig, cwd,
|
|
23
|
+
const { config, userConfig, cwd, name } = opts;
|
|
24
24
|
const isDev = opts.env === types_1.Env.development;
|
|
25
25
|
const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
|
|
26
26
|
const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
|
|
@@ -115,25 +115,8 @@ function addJavaScriptRules(opts) {
|
|
|
115
115
|
// TODO: support javascript
|
|
116
116
|
rule
|
|
117
117
|
.use('swc-loader')
|
|
118
|
-
.loader(require.resolve('
|
|
118
|
+
.loader(require.resolve('../loader/swc'))
|
|
119
119
|
.options({
|
|
120
|
-
jsc: {
|
|
121
|
-
parser: {
|
|
122
|
-
syntax: 'typescript',
|
|
123
|
-
dynamicImport: true,
|
|
124
|
-
tsx: true,
|
|
125
|
-
},
|
|
126
|
-
transform: {
|
|
127
|
-
react: {
|
|
128
|
-
runtime: 'automatic',
|
|
129
|
-
pragma: 'React.createElement',
|
|
130
|
-
pragmaFrag: 'React.Fragment',
|
|
131
|
-
throwIfNamespace: true,
|
|
132
|
-
development: env === types_1.Env.development,
|
|
133
|
-
useBuiltins: true,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
120
|
plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
|
|
138
121
|
});
|
|
139
122
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export declare function addManifestPlugin(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addManifestPlugin = void 0;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
|
|
15
|
+
function addManifestPlugin(opts) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { config, userConfig } = opts;
|
|
18
|
+
if (userConfig.manifest) {
|
|
19
|
+
config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
|
|
20
|
+
Object.assign({ fileName: 'asset-manifest.json' }, userConfig.manifest),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.addManifestPlugin = addManifestPlugin;
|
|
@@ -15,11 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.addMiniCSSExtractPlugin = void 0;
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
|
|
18
|
-
const types_1 = require("../types");
|
|
19
18
|
function addMiniCSSExtractPlugin(opts) {
|
|
20
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const { config, userConfig,
|
|
22
|
-
const hash =
|
|
20
|
+
const { config, userConfig, useHash } = opts;
|
|
21
|
+
const hash = useHash ? '.[contenthash:8]' : '';
|
|
23
22
|
if (!userConfig.styleLoader) {
|
|
24
23
|
config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
|
|
25
24
|
{
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { IOpts as IConfigOpts } from './config/config';
|
|
1
2
|
import { IConfig } from './types';
|
|
2
|
-
|
|
3
|
+
declare type IOpts = {
|
|
3
4
|
afterMiddlewares?: any[];
|
|
4
5
|
beforeMiddlewares?: any[];
|
|
5
6
|
onDevCompileDone?: Function;
|
|
@@ -14,6 +15,6 @@ interface IOpts {
|
|
|
14
15
|
cwd: string;
|
|
15
16
|
config: IConfig;
|
|
16
17
|
entry: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
+
} & Pick<IConfigOpts, 'cache'>;
|
|
18
19
|
export declare function dev(opts: IOpts): Promise<void>;
|
|
19
20
|
export {};
|
package/dist/dev.js
CHANGED
|
@@ -14,14 +14,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.dev = void 0;
|
|
16
16
|
const mfsu_1 = require("@umijs/mfsu");
|
|
17
|
+
const path_1 = require("path");
|
|
17
18
|
const webpack_1 = __importDefault(require("../compiled/webpack"));
|
|
18
19
|
const config_1 = require("./config/config");
|
|
19
20
|
const constants_1 = require("./constants");
|
|
20
21
|
const server_1 = require("./server/server");
|
|
21
22
|
const types_1 = require("./types");
|
|
22
23
|
function dev(opts) {
|
|
23
|
-
var _a;
|
|
24
|
-
var
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
var _e;
|
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
const enableMFSU = opts.config.mfsu !== false;
|
|
27
28
|
let mfsu = null;
|
|
@@ -29,6 +30,11 @@ function dev(opts) {
|
|
|
29
30
|
mfsu = new mfsu_1.MFSU({
|
|
30
31
|
implementor: webpack_1.default,
|
|
31
32
|
buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
|
|
33
|
+
depBuildConfig: {
|
|
34
|
+
extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
|
|
35
|
+
},
|
|
36
|
+
mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
|
|
37
|
+
runtimePublicPath: opts.config.runtimePublicPath,
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
const webpackConfig = yield (0, config_1.getConfig)({
|
|
@@ -49,6 +55,8 @@ function dev(opts) {
|
|
|
49
55
|
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
50
56
|
hmr: true,
|
|
51
57
|
analyze: process.env.ANALYZE,
|
|
58
|
+
// disable cache since it's conflict with mfsu
|
|
59
|
+
// cache: opts.cache,
|
|
52
60
|
});
|
|
53
61
|
const depConfig = yield (0, config_1.getConfig)({
|
|
54
62
|
cwd: opts.cwd,
|
|
@@ -58,17 +66,21 @@ function dev(opts) {
|
|
|
58
66
|
hash: true,
|
|
59
67
|
staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
|
|
60
68
|
name: constants_1.MFSU_NAME,
|
|
69
|
+
cache: {
|
|
70
|
+
buildDependencies: (_d = opts.cache) === null || _d === void 0 ? void 0 : _d.buildDependencies,
|
|
71
|
+
cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
|
|
72
|
+
},
|
|
61
73
|
});
|
|
62
|
-
(
|
|
74
|
+
(_e = webpackConfig.resolve).alias || (_e.alias = {});
|
|
63
75
|
// TODO: REMOVE ME
|
|
64
76
|
['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
|
|
65
77
|
// @ts-ignore
|
|
66
78
|
webpackConfig.resolve.alias[dep] = require.resolve(dep);
|
|
67
79
|
});
|
|
68
|
-
mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
|
|
80
|
+
yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
|
|
69
81
|
config: webpackConfig,
|
|
70
82
|
depConfig: depConfig,
|
|
71
|
-
});
|
|
83
|
+
}));
|
|
72
84
|
yield (0, server_1.createServer)({
|
|
73
85
|
webpackConfig,
|
|
74
86
|
userConfig: opts.config,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@swc/core");
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
function getBaseOpts(filename) {
|
|
6
|
+
const isTSFile = filename.endsWith('.ts');
|
|
7
|
+
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
8
|
+
const swcOpts = {
|
|
9
|
+
jsc: {
|
|
10
|
+
parser: {
|
|
11
|
+
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
12
|
+
[isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
|
|
13
|
+
dynamicImport: isTypeScript,
|
|
14
|
+
},
|
|
15
|
+
target: 'es2017',
|
|
16
|
+
transform: {
|
|
17
|
+
react: {
|
|
18
|
+
runtime: 'automatic',
|
|
19
|
+
pragma: 'React.createElement',
|
|
20
|
+
pragmaFrag: 'React.Fragment',
|
|
21
|
+
throwIfNamespace: true,
|
|
22
|
+
development: process.env.NODE_ENV === types_1.Env.development,
|
|
23
|
+
useBuiltins: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
sourceMaps: true,
|
|
28
|
+
};
|
|
29
|
+
return swcOpts;
|
|
30
|
+
}
|
|
31
|
+
function swcLoader(contents) {
|
|
32
|
+
// 启用异步模式
|
|
33
|
+
const callback = this.async();
|
|
34
|
+
const loaderOpts = this.getOptions();
|
|
35
|
+
const swcOpts = Object.assign(Object.assign({}, getBaseOpts(this.resourcePath)), loaderOpts);
|
|
36
|
+
const { sync = false, parseMap = false } = swcOpts;
|
|
37
|
+
try {
|
|
38
|
+
if (sync) {
|
|
39
|
+
const output = (0, core_1.transformSync)(contents, swcOpts);
|
|
40
|
+
callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
(0, core_1.transform)(contents, swcOpts).then((output) => {
|
|
44
|
+
callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
|
|
45
|
+
}, (err) => {
|
|
46
|
+
callback(err);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
callback(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = swcLoader;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuntimePublicPathPlugin = void 0;
|
|
4
|
+
const PLUGIN_NAME = 'RuntimePublicPath';
|
|
5
|
+
// ref: https://gist.github.com/ScriptedAlchemy/60d0c49ce049184f6ce3e86ca351fdca
|
|
6
|
+
class RuntimePublicPathPlugin {
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
|
|
9
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
|
|
10
|
+
// The hook to get the public path ('__webpack_require__.p')
|
|
11
|
+
// https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
|
|
12
|
+
if (module.constructor.name === 'PublicPathRuntimeModule') {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
module._cachedGeneratedCode = `__webpack_require__.p = window.publicPath;`;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RuntimePublicPathPlugin = RuntimePublicPathPlugin;
|
package/dist/schema.js
CHANGED
|
@@ -24,6 +24,7 @@ function getSchemas() {
|
|
|
24
24
|
return {
|
|
25
25
|
alias: (Joi) => Joi.object(),
|
|
26
26
|
autoCSSModules: (Joi) => Joi.boolean(),
|
|
27
|
+
autoprefixer: (Joi) => Joi.object(),
|
|
27
28
|
chainWebpack: (Joi) => Joi.function(),
|
|
28
29
|
copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
|
|
29
30
|
from: Joi.string(),
|
|
@@ -36,28 +37,29 @@ function getSchemas() {
|
|
|
36
37
|
define: (Joi) => Joi.object(),
|
|
37
38
|
depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
38
39
|
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
39
|
-
externals: (Joi) => Joi.alternatives().try(Joi.object().
|
|
40
|
-
Joi.string(),
|
|
41
|
-
Joi.boolean(),
|
|
42
|
-
Joi.object().pattern(/.+/, [Joi.string(), Joi.boolean()]),
|
|
43
|
-
]), Joi.string(), Joi.func().arity(3), Joi.object().regex()),
|
|
40
|
+
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
44
41
|
extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
45
42
|
extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
46
43
|
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
47
44
|
fastRefresh: (Joi) => Joi.boolean(),
|
|
45
|
+
forkTSChecker: (Joi) => Joi.object(),
|
|
48
46
|
hash: (Joi) => Joi.boolean(),
|
|
49
47
|
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
48
|
+
inlineLimit: (Joi) => Joi.number(),
|
|
50
49
|
jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
|
|
51
50
|
jsMinifierOptions: (Joi) => Joi.object(),
|
|
52
51
|
lessLoader: (Joi) => Joi.object(),
|
|
52
|
+
manifest: (Joi) => Joi.object(),
|
|
53
53
|
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
54
54
|
esbuild: Joi.boolean(),
|
|
55
|
+
mfName: Joi.string(),
|
|
55
56
|
}), Joi.boolean()),
|
|
56
57
|
outputPath: (Joi) => Joi.string(),
|
|
57
58
|
postcssLoader: (Joi) => Joi.object(),
|
|
58
59
|
proxy: (Joi) => Joi.object(),
|
|
59
60
|
publicPath: (Joi) => Joi.string(),
|
|
60
61
|
purgeCSS: (Joi) => Joi.object(),
|
|
62
|
+
runtimePublicPath: (Joi) => Joi.object(),
|
|
61
63
|
sassLoader: (Joi) => Joi.object(),
|
|
62
64
|
srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
63
65
|
styleLoader: (Joi) => Joi.object(),
|