@umijs/bundler-webpack 4.0.0-rc.2 → 4.0.0-rc.20

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.
Files changed (112) hide show
  1. package/client/client/client.js +65 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/autoprefixer/browserslist/index.d.ts +2 -0
  4. package/compiled/autoprefixer/index.js +3 -3
  5. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
  6. package/compiled/autoprefixer/postcss/lib/node.d.ts +2 -2
  7. package/compiled/babel-loader/index.js +2 -2
  8. package/compiled/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
  9. package/compiled/copy-webpack-plugin/index.js +12 -12
  10. package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
  11. package/compiled/cssnano/index.js +6 -6
  12. package/compiled/cssnano/package.json +1 -1
  13. package/compiled/express.d.ts +2 -0
  14. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  15. package/compiled/http-proxy-middleware/index.js +10 -10
  16. package/compiled/mini-css-extract-plugin/index.js +440 -401
  17. package/compiled/mini-css-extract-plugin/loader.js +3 -1
  18. package/compiled/mini-css-extract-plugin/utils.js +2 -0
  19. package/compiled/{tapable → react-refresh}/LICENSE +6 -6
  20. package/compiled/react-refresh/index.js +9 -7
  21. package/compiled/react-refresh/package.json +1 -0
  22. package/compiled/terser/index.js +1 -1
  23. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  24. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  25. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  26. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  27. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  28. package/compiled/webpack/RuleSetCompiler.js +1 -0
  29. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  30. package/compiled/webpack/deepImports.json +6 -1
  31. package/compiled/webpack/index.js +5760 -3275
  32. package/compiled/webpack/types.d.ts +606 -171
  33. package/compiled/webpack-manifest-plugin/index.js +1 -1
  34. package/dist/build.d.ts +1 -0
  35. package/dist/build.js +48 -57
  36. package/dist/cli.js +6 -15
  37. package/dist/client/client.js +57 -51
  38. package/dist/config/_sampleFeature.js +6 -17
  39. package/dist/config/assetRules.js +44 -55
  40. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  41. package/dist/config/compressPlugin.js +89 -64
  42. package/dist/config/config.d.ts +2 -0
  43. package/dist/config/config.js +177 -179
  44. package/dist/config/copyPlugin.js +29 -40
  45. package/dist/config/cssRules.js +93 -83
  46. package/dist/config/definePlugin.js +11 -19
  47. package/dist/config/detectDeadCode.js +1 -1
  48. package/dist/config/detectDeadCodePlugin.js +21 -22
  49. package/dist/config/fastRefreshPlugin.js +11 -22
  50. package/dist/config/forkTSCheckerPlugin.js +11 -22
  51. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  52. package/dist/config/ignorePlugin.js +10 -21
  53. package/dist/config/javaScriptRules.d.ts +1 -0
  54. package/dist/config/javaScriptRules.js +152 -138
  55. package/dist/config/manifestPlugin.js +10 -18
  56. package/dist/config/miniCSSExtractPlugin.js +12 -23
  57. package/dist/config/nodePolyfill.js +14 -20
  58. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  59. package/dist/config/nodePrefixPlugin.js +14 -0
  60. package/dist/config/progressPlugin.js +7 -18
  61. package/dist/config/purgecssWebpackPlugin.js +15 -26
  62. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  63. package/dist/config/svgRules.js +44 -47
  64. package/dist/constants.d.ts +1 -0
  65. package/dist/constants.js +7 -1
  66. package/dist/dev.d.ts +4 -0
  67. package/dist/dev.js +115 -94
  68. package/dist/index.d.ts +4 -1
  69. package/dist/index.js +5 -1
  70. package/dist/loader/svgr.js +4 -13
  71. package/dist/loader/swc.js +9 -14
  72. package/dist/plugins/ProgressPlugin.js +2 -2
  73. package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
  74. package/dist/schema.js +29 -13
  75. package/dist/server/server.d.ts +2 -1
  76. package/dist/server/server.js +164 -148
  77. package/dist/server/ws.d.ts +5 -2
  78. package/dist/swcPlugins/autoCSSModules.js +3 -1
  79. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  80. package/dist/swcPlugins/changeImportFromString.js +10 -0
  81. package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
  82. package/dist/swcPlugins/lockCoreJS.js +3 -2
  83. package/dist/types.d.ts +4 -0
  84. package/dist/types.js +1 -0
  85. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  86. package/dist/utils/getEsBuildTarget.js +12 -0
  87. package/package.json +32 -34
  88. package/compiled/css-loader/LICENSE +0 -20
  89. package/compiled/css-loader/api.js +0 -102
  90. package/compiled/css-loader/getUrl.js +0 -29
  91. package/compiled/css-loader/index.js +0 -2
  92. package/compiled/css-loader/noSourceMaps.js +0 -5
  93. package/compiled/css-loader/package.json +0 -1
  94. package/compiled/css-loader/sourceMaps.js +0 -22
  95. package/compiled/express/LICENSE +0 -24
  96. package/compiled/express/body-parser/index.d.ts +0 -104
  97. package/compiled/express/connect/index.d.ts +0 -93
  98. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  99. package/compiled/express/index.d.ts +0 -133
  100. package/compiled/express/index.js +0 -321
  101. package/compiled/express/mime/index.d.ts +0 -35
  102. package/compiled/express/package.json +0 -1
  103. package/compiled/express/qs/index.d.ts +0 -62
  104. package/compiled/express/range-parser/index.d.ts +0 -35
  105. package/compiled/express/serve-static/index.d.ts +0 -108
  106. package/compiled/less/index.js +0 -31
  107. package/compiled/less/package.json +0 -1
  108. package/compiled/tapable/index.js +0 -1
  109. package/compiled/tapable/package.json +0 -1
  110. package/compiled/tapable/tapable.d.ts +0 -116
  111. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  112. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -65
@@ -1 +1 @@
1
- (function(){"use strict";var e={886: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},863: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(886);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 normalizePath=e=>{if(!e.endsWith("/")){return`${e}/`}return e};const t={name:d?normalizePath(d)+e.name:e.name,path:f?normalizePath(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},25: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(863);Object.defineProperty(t,"getCompilerHooks",{enumerable:true,get:function(){return r.getCompilerHooks}});const u=new Map;const l={assetHookStage:Infinity,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:this.options.assetHookStage};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__(25);module.exports=s})();
1
+ (function(){"use strict";var e={156: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},874: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(156);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 normalizePath=e=>{if(!e.endsWith("/")){return`${e}/`}return e};const t={name:d?normalizePath(d)+e.name:e.name,path:f?normalizePath(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},131: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(205));const a=s(874);Object.defineProperty(t,"getCompilerHooks",{enumerable:true,get:function(){return a.getCompilerHooks}});const r=new Map;const u={assetHookStage:Infinity,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({},u,e)}apply(e){var t,s;const n={};const u=o.resolve(((t=e.options.output)===null||t===void 0?void 0:t.path)||"./",this.options.fileName);const l=o.relative(((s=e.options.output)===null||s===void 0?void 0:s.path)||"./",u);const c=a.beforeRunHook.bind(this,{emitCountMap:r,manifestFileName:u});const p=a.emitHook.bind(this,{compiler:e,emitCountMap:r,manifestAssetId:l,manifestFileName:u,moduleAssets:n,options:this.options});const m=a.normalModuleLoaderHook.bind(this,{moduleAssets:n});const f={name:"WebpackManifestPlugin",stage:this.options.assetHookStage};e.hooks.compilation.tap(f,(e=>{const t=!i.default.getCompilationHooks?e.hooks.normalModuleLoader:i.default.getCompilationHooks(e).loader;t.tap(f,m)}));if(this.options.useLegacyEmit===true){e.hooks.emit.tap(f,p)}else{e.hooks.thisCompilation.tap(f,(e=>{e.hooks.processAssets.tap(f,(()=>p(e)))}))}e.hooks.run.tapAsync(f,c);e.hooks.watchRun.tapAsync(f,c)}}t.WebpackManifestPlugin=WebpackManifestPlugin},205:function(e){e.exports=require("../webpack/NormalModule")},535:function(e){e.exports=require("@umijs/bundler-utils/compiled/tapable")},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__(131);module.exports=s})();
package/dist/build.d.ts CHANGED
@@ -3,6 +3,7 @@ import { IOpts as IConfigOpts } from './config/config';
3
3
  import { IConfig } from './types';
4
4
  declare type IOpts = {
5
5
  cwd: string;
6
+ rootDir?: string;
6
7
  entry: Record<string, string>;
7
8
  config: IConfig;
8
9
  onBuildComplete?: Function;
package/dist/build.js CHANGED
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,56 +8,56 @@ const utils_1 = require("@umijs/utils");
17
8
  const webpack_1 = __importDefault(require("../compiled/webpack"));
18
9
  const config_1 = require("./config/config");
19
10
  const types_1 = require("./types");
20
- function build(opts) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const webpackConfig = yield (0, config_1.getConfig)({
23
- cwd: opts.cwd,
24
- env: types_1.Env.production,
25
- entry: opts.entry,
26
- userConfig: opts.config,
27
- analyze: process.env.ANALYZE,
28
- babelPreset: opts.babelPreset,
29
- extraBabelPlugins: [
30
- ...(opts.beforeBabelPlugins || []),
31
- ...(opts.extraBabelPlugins || []),
32
- ],
33
- extraBabelPresets: [
34
- ...(opts.beforeBabelPresets || []),
35
- ...(opts.extraBabelPresets || []),
36
- ],
37
- chainWebpack: opts.chainWebpack,
38
- modifyWebpackConfig: opts.modifyWebpackConfig,
39
- cache: opts.cache,
40
- });
41
- let isFirstCompile = true;
42
- return new Promise((resolve, reject) => {
43
- utils_1.rimraf.sync(webpackConfig.output.path);
44
- const compiler = (0, webpack_1.default)(webpackConfig);
45
- compiler.run((err, stats) => {
46
- var _a;
47
- (_a = opts.onBuildComplete) === null || _a === void 0 ? void 0 : _a.call(opts, {
48
- err,
49
- stats,
50
- isFirstCompile,
51
- time: stats ? stats.endTime - stats.startTime : null,
52
- });
53
- isFirstCompile = false;
54
- if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
55
- if (err) {
56
- // console.error(err);
57
- reject(err);
58
- }
59
- if (stats) {
60
- const errorMsg = stats.toString('errors-only');
61
- // console.error(errorMsg);
62
- reject(new Error(errorMsg));
63
- }
11
+ async function build(opts) {
12
+ const webpackConfig = await (0, config_1.getConfig)({
13
+ cwd: opts.cwd,
14
+ rootDir: opts.rootDir,
15
+ env: types_1.Env.production,
16
+ entry: opts.entry,
17
+ userConfig: opts.config,
18
+ analyze: process.env.ANALYZE,
19
+ babelPreset: opts.babelPreset,
20
+ extraBabelPlugins: [
21
+ ...(opts.beforeBabelPlugins || []),
22
+ ...(opts.extraBabelPlugins || []),
23
+ ],
24
+ extraBabelPresets: [
25
+ ...(opts.beforeBabelPresets || []),
26
+ ...(opts.extraBabelPresets || []),
27
+ ],
28
+ extraBabelIncludes: opts.config.extraBabelIncludes,
29
+ chainWebpack: opts.chainWebpack,
30
+ modifyWebpackConfig: opts.modifyWebpackConfig,
31
+ cache: opts.cache,
32
+ });
33
+ let isFirstCompile = true;
34
+ return new Promise((resolve, reject) => {
35
+ utils_1.rimraf.sync(webpackConfig.output.path);
36
+ const compiler = (0, webpack_1.default)(webpackConfig);
37
+ compiler.run((err, stats) => {
38
+ var _a;
39
+ (_a = opts.onBuildComplete) === null || _a === void 0 ? void 0 : _a.call(opts, {
40
+ err,
41
+ stats,
42
+ isFirstCompile,
43
+ time: stats ? stats.endTime - stats.startTime : null,
44
+ });
45
+ isFirstCompile = false;
46
+ if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
47
+ if (err) {
48
+ // console.error(err);
49
+ reject(err);
64
50
  }
65
- else {
66
- resolve(stats);
51
+ if (stats) {
52
+ const errorMsg = stats.toString('errors-only');
53
+ // console.error(errorMsg);
54
+ reject(new Error(errorMsg));
67
55
  }
68
- compiler.close(() => { });
69
- });
56
+ }
57
+ else {
58
+ resolve(stats);
59
+ }
60
+ compiler.close(() => { });
70
61
  });
71
62
  });
72
63
  }
package/dist/cli.js CHANGED
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -40,11 +31,11 @@ if ((0, fs_1.existsSync)(configFile)) {
40
31
  }
41
32
  Object.assign(config, args);
42
33
  if (command === 'build') {
43
- (() => __awaiter(void 0, void 0, void 0, function* () {
34
+ (async () => {
44
35
  process.env.NODE_ENV = 'production';
45
36
  (0, assert_1.default)(entry, `Build failed: entry not found.`);
46
37
  try {
47
- yield (0, build_1.build)({
38
+ await (0, build_1.build)({
48
39
  config,
49
40
  cwd,
50
41
  entry: {
@@ -55,14 +46,14 @@ if (command === 'build') {
55
46
  catch (e) {
56
47
  console.error(e);
57
48
  }
58
- }))();
49
+ })();
59
50
  }
60
51
  else if (command === 'dev') {
61
- (() => __awaiter(void 0, void 0, void 0, function* () {
52
+ (async () => {
62
53
  process.env.NODE_ENV = 'development';
63
54
  try {
64
55
  (0, assert_1.default)(entry, `Build failed: entry not found.`);
65
- yield (0, dev_1.dev)({
56
+ await (0, dev_1.dev)({
66
57
  config,
67
58
  cwd,
68
59
  port: process.env.PORT,
@@ -77,7 +68,7 @@ else if (command === 'dev') {
77
68
  catch (e) {
78
69
  console.error(e);
79
70
  }
80
- }))();
71
+ })();
81
72
  }
82
73
  else {
83
74
  error(`Unsupported command ${command}.`);
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
27
  };
@@ -37,15 +32,30 @@ const ErrorOverlay = __importStar(require("react-error-overlay"));
37
32
  const constants_1 = require("../constants");
38
33
  const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
39
34
  console.log('[webpack] connecting...');
35
+ function getHost() {
36
+ if (process.env.SOCKET_SERVER) {
37
+ return new URL(process.env.SOCKET_SERVER);
38
+ }
39
+ return location;
40
+ }
41
+ function getSocketUrl() {
42
+ let h = getHost();
43
+ const host = h.host;
44
+ const isHttps = h.protocol === 'https:';
45
+ return `${isHttps ? 'wss' : 'ws'}://${host}`;
46
+ }
47
+ function getPingUrl() {
48
+ const h = getHost();
49
+ return `${h.protocol}//${h.host}/__umi_ping`;
50
+ }
40
51
  let pingTimer = null;
41
- const host = location.host;
42
- const wsUrl = `ws://${host}`;
43
52
  let isFirstCompilation = true;
44
53
  let mostRecentCompilationHash = null;
45
54
  let hasCompileErrors = false;
46
55
  let hadRuntimeError = false;
47
- const socket = new WebSocket(wsUrl, 'webpack-hmr');
48
- socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
56
+ const pingUrl = getPingUrl();
57
+ const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
58
+ socket.addEventListener('message', async ({ data }) => {
49
59
  data = JSON.parse(data);
50
60
  if (data.type === 'connected') {
51
61
  console.log(`[webpack] connected.`);
@@ -56,28 +66,26 @@ socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void
56
66
  else {
57
67
  handleMessage(data).catch(console.error);
58
68
  }
59
- }));
60
- function waitForSuccessfulPing(ms = 1000) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- // eslint-disable-next-line no-constant-condition
63
- while (true) {
64
- try {
65
- yield fetch(`/__umi_ping`);
66
- break;
67
- }
68
- catch (e) {
69
- yield new Promise((resolve) => setTimeout(resolve, ms));
70
- }
69
+ });
70
+ async function waitForSuccessfulPing(ms = 1000) {
71
+ // eslint-disable-next-line no-constant-condition
72
+ while (true) {
73
+ try {
74
+ await fetch(pingUrl);
75
+ break;
71
76
  }
72
- });
77
+ catch (e) {
78
+ await new Promise((resolve) => setTimeout(resolve, ms));
79
+ }
80
+ }
73
81
  }
74
- socket.addEventListener('close', () => __awaiter(void 0, void 0, void 0, function* () {
82
+ socket.addEventListener('close', async () => {
75
83
  if (pingTimer)
76
84
  clearInterval(pingTimer);
77
85
  console.info('[webpack] Dev server disconnected. Polling for restart...');
78
- yield waitForSuccessfulPing();
86
+ await waitForSuccessfulPing();
79
87
  location.reload();
80
- }));
88
+ });
81
89
  ErrorOverlay.startReportingRuntimeErrors({
82
90
  onError: function () {
83
91
  hadRuntimeError = true;
@@ -215,25 +223,23 @@ function tryApplyUpdates(onHotUpdateSuccess) {
215
223
  handleApplyUpdates(err, null);
216
224
  });
217
225
  }
218
- function handleMessage(payload) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- // console.log('[payload]', payload);
221
- switch (payload.type) {
222
- case constants_1.MESSAGE_TYPE.hash:
223
- handleAvailableHash(payload.data);
224
- break;
225
- case constants_1.MESSAGE_TYPE.stillOk:
226
- case constants_1.MESSAGE_TYPE.ok:
227
- handleSuccess();
228
- break;
229
- case constants_1.MESSAGE_TYPE.errors:
230
- handleErrors(payload.data);
231
- break;
232
- case constants_1.MESSAGE_TYPE.warnings:
233
- handleWarnings(payload.data);
234
- break;
235
- default:
236
- // Do nothing
237
- }
238
- });
226
+ async function handleMessage(payload) {
227
+ // console.log('[payload]', payload);
228
+ switch (payload.type) {
229
+ case constants_1.MESSAGE_TYPE.hash:
230
+ handleAvailableHash(payload.data);
231
+ break;
232
+ case constants_1.MESSAGE_TYPE.stillOk:
233
+ case constants_1.MESSAGE_TYPE.ok:
234
+ handleSuccess();
235
+ break;
236
+ case constants_1.MESSAGE_TYPE.errors:
237
+ handleErrors(payload.data);
238
+ break;
239
+ case constants_1.MESSAGE_TYPE.warnings:
240
+ handleWarnings(payload.data);
241
+ break;
242
+ default:
243
+ // Do nothing
244
+ }
239
245
  }
@@ -1,22 +1,11 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addSampleFeature = void 0;
13
- function addSampleFeature(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig, cwd, env } = opts;
16
- config;
17
- userConfig;
18
- cwd;
19
- env;
20
- });
4
+ async function addSampleFeature(opts) {
5
+ const { config, userConfig, cwd, env } = opts;
6
+ config;
7
+ userConfig;
8
+ cwd;
9
+ env;
21
10
  }
22
11
  exports.addSampleFeature = addSampleFeature;
@@ -1,61 +1,50 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addAssetRules = void 0;
13
- function addAssetRules(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig } = opts;
16
- const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
17
- const rule = config.module.rule('asset');
18
- rule
19
- .oneOf('avif')
20
- .test(/\.avif$/)
21
- .type('asset')
22
- .mimetype('image/avif')
23
- .parser({
24
- dataUrlCondition: {
25
- maxSize: inlineLimit,
26
- },
27
- })
28
- .generator({
29
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
30
- });
31
- rule
32
- .oneOf('image')
33
- .test(/\.(bmp|gif|jpg|jpeg|png)$/)
34
- .type('asset')
35
- .parser({
36
- dataUrlCondition: {
37
- maxSize: inlineLimit,
38
- },
39
- })
40
- .generator({
41
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
42
- });
43
- const fallback = rule
44
- .oneOf('fallback')
45
- .exclude.add(/^$/) /* handle data: resources */
46
- .add(/\.(js|mjs|jsx|ts|tsx)$/)
47
- .add(/\.(css|less|sass|scss|stylus)$/)
48
- .add(/\.html$/)
49
- .add(/\.json$/);
50
- if (userConfig.mdx) {
51
- fallback.add(/\.mdx?$/);
52
- }
53
- fallback
54
- .end()
55
- .type('asset/resource')
56
- .generator({
57
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
58
- });
4
+ async function addAssetRules(opts) {
5
+ const { config, userConfig } = opts;
6
+ const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
7
+ const rule = config.module.rule('asset');
8
+ rule
9
+ .oneOf('avif')
10
+ .test(/\.avif$/)
11
+ .type('asset')
12
+ .mimetype('image/avif')
13
+ .parser({
14
+ dataUrlCondition: {
15
+ maxSize: inlineLimit,
16
+ },
17
+ })
18
+ .generator({
19
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
20
+ });
21
+ rule
22
+ .oneOf('image')
23
+ .test(/\.(bmp|gif|jpg|jpeg|png)$/)
24
+ .type('asset')
25
+ .parser({
26
+ dataUrlCondition: {
27
+ maxSize: inlineLimit,
28
+ },
29
+ })
30
+ .generator({
31
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
32
+ });
33
+ const fallback = rule
34
+ .oneOf('fallback')
35
+ .exclude.add(/^$/) /* handle data: resources */
36
+ .add(/\.(js|mjs|jsx|ts|tsx)$/)
37
+ .add(/\.(css|less|sass|scss|stylus)$/)
38
+ .add(/\.html$/)
39
+ .add(/\.json$/);
40
+ if (userConfig.mdx) {
41
+ fallback.add(/\.mdx?$/);
42
+ }
43
+ fallback
44
+ .end()
45
+ .type('asset/resource')
46
+ .generator({
47
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
59
48
  });
60
49
  }
61
50
  exports.addAssetRules = addAssetRules;
@@ -1,30 +1,19 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addBundleAnalyzerPlugin = void 0;
13
4
  // @ts-ignore
14
5
  const webpack_bundle_analyzer_1 = require("@umijs/bundler-webpack/compiled/webpack-bundle-analyzer");
15
- function addBundleAnalyzerPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config } = opts;
18
- config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
19
- // https://github.com/webpack-contrib/webpack-bundle-analyzer
20
- {
21
- analyzerMode: 'server',
22
- analyzerPort: process.env.ANALYZE_PORT || 8888,
23
- openAnalyzer: false,
24
- logLevel: 'info',
25
- defaultSizes: 'parsed',
26
- },
27
- ]);
28
- });
6
+ async function addBundleAnalyzerPlugin(opts) {
7
+ const { config } = opts;
8
+ config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
9
+ // https://github.com/webpack-contrib/webpack-bundle-analyzer
10
+ {
11
+ analyzerMode: 'server',
12
+ analyzerPort: process.env.ANALYZE_PORT || 8888,
13
+ openAnalyzer: false,
14
+ logLevel: 'info',
15
+ defaultSizes: 'parsed',
16
+ },
17
+ ]);
29
18
  }
30
19
  exports.addBundleAnalyzerPlugin = addBundleAnalyzerPlugin;