@umijs/bundler-webpack 4.0.0-beta.14 → 4.0.0-beta.18

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 (34) hide show
  1. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  2. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  3. package/compiled/fork-ts-checker-webpack-plugin/index.js +49 -0
  4. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  5. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  6. package/compiled/webpack-manifest-plugin/index.js +1 -0
  7. package/compiled/webpack-manifest-plugin/package.json +1 -0
  8. package/dist/build.d.ts +3 -2
  9. package/dist/build.js +1 -0
  10. package/dist/cli.js +4 -7
  11. package/dist/config/assetRules.js +6 -2
  12. package/dist/config/config.d.ts +6 -2
  13. package/dist/config/config.js +36 -3
  14. package/dist/config/cssRules.js +1 -1
  15. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  16. package/dist/config/forkTSCheckerPlugin.js +34 -0
  17. package/dist/config/harmonyLinkingErrorPlugin.js +4 -1
  18. package/dist/config/javaScriptRules.js +14 -19
  19. package/dist/config/manifestPlugin.d.ts +11 -0
  20. package/dist/config/manifestPlugin.js +25 -0
  21. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  22. package/dist/config/miniCSSExtractPlugin.js +2 -3
  23. package/dist/dev.d.ts +3 -2
  24. package/dist/dev.js +9 -3
  25. package/dist/loader/swc.d.ts +4 -0
  26. package/dist/loader/swc.js +54 -0
  27. package/dist/plugins/RuntimePublicPathPlugin.js +1 -0
  28. package/dist/schema.js +9 -5
  29. package/dist/server/server.js +5 -3
  30. package/dist/types.d.ts +5 -0
  31. package/package.json +13 -8
  32. package/compiled/swc-loader/LICENSE +0 -25
  33. package/compiled/swc-loader/index.js +0 -1
  34. 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
- interface IOpts {
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
@@ -36,6 +36,7 @@ function build(opts) {
36
36
  ],
37
37
  chainWebpack: opts.chainWebpack,
38
38
  modifyWebpackConfig: opts.modifyWebpackConfig,
39
+ cache: opts.cache,
39
40
  });
40
41
  let isFirstCompile = true;
41
42
  return new Promise((resolve, reject) => {
package/dist/cli.js CHANGED
@@ -22,7 +22,7 @@ const dev_1 = require("./dev");
22
22
  const args = (0, utils_1.yParser)(process.argv.slice(2), {});
23
23
  const command = args._[0];
24
24
  const cwd = process.cwd();
25
- const entry = tryPaths([
25
+ const entry = (0, utils_1.tryPaths)([
26
26
  (0, path_1.join)(cwd, 'src/index.tsx'),
27
27
  (0, path_1.join)(cwd, 'src/index.ts'),
28
28
  (0, path_1.join)(cwd, 'index.tsx'),
@@ -69,6 +69,9 @@ else if (command === 'dev') {
69
69
  entry: {
70
70
  [getEntryKey(entry)]: entry,
71
71
  },
72
+ cache: {
73
+ buildDependencies: [].filter(Boolean),
74
+ },
72
75
  });
73
76
  }
74
77
  catch (e) {
@@ -82,12 +85,6 @@ else {
82
85
  function error(msg) {
83
86
  console.error(utils_1.chalk.red(msg));
84
87
  }
85
- function tryPaths(paths) {
86
- for (const path of paths) {
87
- if ((0, fs_1.existsSync)(path))
88
- return path;
89
- }
90
- }
91
88
  function getEntryKey(path) {
92
89
  return (0, path_1.basename)(path, (0, path_1.extname)(path));
93
90
  }
@@ -40,13 +40,17 @@ function addAssetRules(opts) {
40
40
  .generator({
41
41
  filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
42
42
  });
43
- rule
43
+ const fallback = rule
44
44
  .oneOf('fallback')
45
45
  .exclude.add(/^$/) /* handle data: resources */
46
46
  .add(/\.(js|mjs|jsx|ts|tsx)$/)
47
47
  .add(/\.(css|less|sass|scss|stylus)$/)
48
48
  .add(/\.html$/)
49
- .add(/\.json$/)
49
+ .add(/\.json$/);
50
+ if (userConfig.mdx) {
51
+ fallback.add(/\.mdx?$/);
52
+ }
53
+ fallback
50
54
  .end()
51
55
  .type('asset/resource')
52
56
  .generator({
@@ -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 {};
@@ -27,9 +27,11 @@ const copyPlugin_1 = require("./copyPlugin");
27
27
  const cssRules_1 = require("./cssRules");
28
28
  const definePlugin_1 = require("./definePlugin");
29
29
  const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
30
+ const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
30
31
  const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
31
32
  const ignorePlugin_1 = require("./ignorePlugin");
32
33
  const javaScriptRules_1 = require("./javaScriptRules");
34
+ const manifestPlugin_1 = require("./manifestPlugin");
33
35
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
34
36
  const nodePolyfill_1 = require("./nodePolyfill");
35
37
  const progressPlugin_1 = require("./progressPlugin");
@@ -43,6 +45,7 @@ function getConfig(opts) {
43
45
  userConfig.targets = userConfig.targets || {
44
46
  chrome: 80,
45
47
  };
48
+ const useHash = !!(opts.hash || (userConfig.hash && !isDev));
46
49
  const applyOpts = {
47
50
  name: opts.name,
48
51
  config,
@@ -55,6 +58,7 @@ function getConfig(opts) {
55
58
  browsers: (0, browsersList_1.getBrowsersList)({
56
59
  targets: userConfig.targets,
57
60
  }),
61
+ useHash,
58
62
  staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
59
63
  };
60
64
  // mode
@@ -76,7 +80,6 @@ function getConfig(opts) {
76
80
  : userConfig.devtool);
77
81
  // output
78
82
  const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
79
- const useHash = opts.hash || (userConfig.hash && !isDev);
80
83
  const disableCompress = process.env.COMPRESS === 'none';
81
84
  config.output
82
85
  .path(absOutputPath)
@@ -132,10 +135,12 @@ function getConfig(opts) {
132
135
  yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
133
136
  // progress
134
137
  yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
138
+ // fork-ts-checker
139
+ yield (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
135
140
  // copy
136
141
  yield (0, copyPlugin_1.addCopyPlugin)(applyOpts);
137
- // TODO: friendly-error
138
- // TODO: manifest
142
+ // manifest
143
+ yield (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
139
144
  // hmr
140
145
  if (isDev && opts.hmr) {
141
146
  config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
@@ -150,6 +155,34 @@ function getConfig(opts) {
150
155
  if (userConfig.runtimePublicPath) {
151
156
  config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
152
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
+ }
153
186
  // analyzer
154
187
  if (opts.analyze) {
155
188
  yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
@@ -56,7 +56,7 @@ function addCSSRules(opts) {
56
56
  }
57
57
  else {
58
58
  rule
59
- .use('mini-css-extract-plugin-loader')
59
+ .use('mini-css-extract-plugin')
60
60
  .loader(require.resolve('@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader'))
61
61
  .options({
62
62
  publicPath: './',
@@ -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;
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addHarmonyLinkingErrorPlugin = void 0;
13
13
  // ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
14
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\)/;
15
17
  class HarmonyLinkingErrorPlugin {
16
18
  apply(compiler) {
17
19
  compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
@@ -21,7 +23,8 @@ class HarmonyLinkingErrorPlugin {
21
23
  const harmonyLinkingErrors = compilation.warnings.filter((w) => {
22
24
  return (w.name === 'ModuleDependencyWarning' &&
23
25
  !w.module.resource.includes('node_modules') &&
24
- w.message.includes(LINKING_ERROR_TAG));
26
+ w.message.includes(LINKING_ERROR_TAG) &&
27
+ !CSS_NO_EXPORTS.test(w.message));
25
28
  });
26
29
  if (!harmonyLinkingErrors.length) {
27
30
  return;
@@ -19,8 +19,9 @@ const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules")
19
19
  const types_1 = require("../types");
20
20
  const depMatch_1 = require("../utils/depMatch");
21
21
  function addJavaScriptRules(opts) {
22
+ var _a, _b;
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- const { config, userConfig, cwd, env, name } = opts;
24
+ const { config, userConfig, cwd, name } = opts;
24
25
  const isDev = opts.env === types_1.Env.development;
25
26
  const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
26
27
  const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
@@ -54,6 +55,9 @@ function addJavaScriptRules(opts) {
54
55
  })
55
56
  .end(),
56
57
  ];
58
+ if (userConfig.mdx) {
59
+ srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
60
+ }
57
61
  const depRules = [
58
62
  config.module
59
63
  .rule('dep')
@@ -115,25 +119,8 @@ function addJavaScriptRules(opts) {
115
119
  // TODO: support javascript
116
120
  rule
117
121
  .use('swc-loader')
118
- .loader(require.resolve('../../compiled/swc-loader'))
122
+ .loader(require.resolve('../loader/swc'))
119
123
  .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
124
  plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
138
125
  });
139
126
  }
@@ -141,6 +128,14 @@ function addJavaScriptRules(opts) {
141
128
  throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
142
129
  }
143
130
  });
131
+ if (userConfig.mdx) {
132
+ config.module
133
+ .rule('mdx')
134
+ .test(/\.mdx?$/)
135
+ .use('mdx-loader')
136
+ .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
137
+ .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
138
+ }
144
139
  const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
145
140
  depRules.forEach((_rule) => {
146
141
  if (depTranspiler === types_1.Transpiler.none) {
@@ -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;
@@ -5,6 +5,7 @@ interface IOpts {
5
5
  userConfig: IConfig;
6
6
  cwd: string;
7
7
  env: Env;
8
+ useHash: boolean;
8
9
  }
9
10
  export declare function addMiniCSSExtractPlugin(opts: IOpts): Promise<void>;
10
11
  export {};
@@ -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, env } = opts;
22
- const hash = env !== types_1.Env.development && userConfig.hash ? '.[contenthash:8]' : '';
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
- interface IOpts {
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, _b, _c;
24
- var _d;
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;
@@ -54,6 +55,7 @@ function dev(opts) {
54
55
  modifyWebpackConfig: opts.modifyWebpackConfig,
55
56
  hmr: true,
56
57
  analyze: process.env.ANALYZE,
58
+ cache: opts.cache,
57
59
  });
58
60
  const depConfig = yield (0, config_1.getConfig)({
59
61
  cwd: opts.cwd,
@@ -63,8 +65,12 @@ function dev(opts) {
63
65
  hash: true,
64
66
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
65
67
  name: constants_1.MFSU_NAME,
68
+ cache: {
69
+ buildDependencies: (_d = opts.cache) === null || _d === void 0 ? void 0 : _d.buildDependencies,
70
+ cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
71
+ },
66
72
  });
67
- (_d = webpackConfig.resolve).alias || (_d.alias = {});
73
+ (_e = webpackConfig.resolve).alias || (_e.alias = {});
68
74
  // TODO: REMOVE ME
69
75
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
70
76
  // @ts-ignore
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import { SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string): void;
4
+ export default swcLoader;
@@ -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;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RuntimePublicPathPlugin = void 0;
4
4
  const PLUGIN_NAME = 'RuntimePublicPath';
5
+ // ref: https://gist.github.com/ScriptedAlchemy/60d0c49ce049184f6ce3e86ca351fdca
5
6
  class RuntimePublicPathPlugin {
6
7
  apply(compiler) {
7
8
  compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
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,20 +37,23 @@ 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().pattern(/.+/, [
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
+ mdx: (Joi) => Joi.object({
54
+ loader: Joi.string(),
55
+ loaderOptions: Joi.object(),
56
+ }),
53
57
  mfsu: (Joi) => Joi.alternatives(Joi.object({
54
58
  esbuild: Joi.boolean(),
55
59
  mfName: Joi.string(),
@@ -30,8 +30,10 @@ function createServer(opts) {
30
30
  // basename middleware
31
31
  app.use((req, _res, next) => {
32
32
  const { url, path } = req;
33
- const { basename } = userConfig;
34
- if (basename !== '/' && url.startsWith(basename)) {
33
+ const { basename, history } = userConfig;
34
+ if ((history === null || history === void 0 ? void 0 : history.type) === 'browser' &&
35
+ basename !== '/' &&
36
+ url.startsWith(basename)) {
35
37
  req.url = url.slice(basename.length);
36
38
  req.path = path.slice(basename.length);
37
39
  }
@@ -167,7 +169,7 @@ function createServer(opts) {
167
169
  const port = opts.port || 8000;
168
170
  server.listen(port, () => {
169
171
  const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
170
- utils_1.logger.ready(`App listening at ${utils_1.chalk.green.bold(`http://${host}:${port}`)}`);
172
+ utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`http://${host}:${port}`)}`);
171
173
  });
172
174
  return server;
173
175
  });
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Config as SwcConfig } from '@swc/core';
1
2
  import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
2
3
  import { Configuration } from '../compiled/webpack';
3
4
  import Config from '../compiled/webpack-5-chain';
@@ -98,4 +99,8 @@ export interface IConfig {
98
99
  writeToDisk?: boolean;
99
100
  [key: string]: any;
100
101
  }
102
+ export interface SwcOptions extends SwcConfig {
103
+ sync?: boolean;
104
+ parseMap?: boolean;
105
+ }
101
106
  export {};