@umijs/bundler-webpack 4.0.4 → 4.0.7

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/dist/build.js CHANGED
@@ -5,10 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.build = void 0;
7
7
  const utils_1 = require("@umijs/utils");
8
+ const path_1 = require("path");
8
9
  const webpack_1 = __importDefault(require("../compiled/webpack"));
9
10
  const config_1 = require("./config/config");
10
11
  const types_1 = require("./types");
11
12
  async function build(opts) {
13
+ const cacheDirectoryPath = (0, path_1.resolve)(opts.rootDir || opts.cwd, opts.config.cacheDirectoryPath || 'node_modules/.cache');
12
14
  const webpackConfig = await (0, config_1.getConfig)({
13
15
  cwd: opts.cwd,
14
16
  rootDir: opts.rootDir,
@@ -28,7 +30,12 @@ async function build(opts) {
28
30
  extraBabelIncludes: opts.config.extraBabelIncludes,
29
31
  chainWebpack: opts.chainWebpack,
30
32
  modifyWebpackConfig: opts.modifyWebpackConfig,
31
- cache: opts.cache,
33
+ cache: opts.cache
34
+ ? {
35
+ ...opts.cache,
36
+ cacheDirectory: (0, path_1.join)(cacheDirectoryPath, 'bundler-webpack'),
37
+ }
38
+ : undefined,
32
39
  });
33
40
  let isFirstCompile = true;
34
41
  return new Promise((resolve, reject) => {
@@ -9,15 +9,22 @@ async function addCopyPlugin(opts) {
9
9
  const copyPatterns = [
10
10
  (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
11
11
  from: (0, path_1.join)(cwd, 'public'),
12
+ // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
13
+ // Set minimized so terser will not do minimize
14
+ info: { minimized: true },
12
15
  },
13
16
  ...(userConfig.copy
14
17
  ? (_a = userConfig.copy) === null || _a === void 0 ? void 0 : _a.map((pattern) => {
15
18
  if (typeof pattern === 'string') {
16
- return (0, path_1.resolve)(cwd, pattern);
19
+ return {
20
+ from: (0, path_1.resolve)(cwd, pattern),
21
+ info: { minimized: true },
22
+ };
17
23
  }
18
24
  return {
19
25
  from: (0, path_1.resolve)(cwd, pattern.from),
20
26
  to: (0, path_1.resolve)(cwd, pattern.to),
27
+ info: { minimized: true },
21
28
  };
22
29
  })
23
30
  : []),
@@ -8,6 +8,7 @@ interface IOpts {
8
8
  }
9
9
  export declare function resolveDefine(opts: {
10
10
  define: any;
11
+ publicPath?: string;
11
12
  }): {
12
13
  'process.env': Record<string, any>;
13
14
  };
@@ -11,6 +11,9 @@ function resolveDefine(opts) {
11
11
  env[key] = process.env[key];
12
12
  }
13
13
  });
14
+ // Useful for resolving the correct path to static assets in `public`.
15
+ // For example, <img src={process.env.PUBLIC_PATH + '/img/logo.png'} />.
16
+ env.PUBLIC_PATH = opts.publicPath || '/';
14
17
  for (const key in env) {
15
18
  env[key] = JSON.stringify(env[key]);
16
19
  }
@@ -31,6 +34,7 @@ async function addDefinePlugin(opts) {
31
34
  config.plugin('define').use(webpack_1.DefinePlugin, [
32
35
  resolveDefine({
33
36
  define: userConfig.define || {},
37
+ publicPath: userConfig.publicPath,
34
38
  }),
35
39
  ]);
36
40
  }
package/dist/dev.js CHANGED
@@ -25,6 +25,7 @@ exports.stripUndefined = stripUndefined;
25
25
  async function dev(opts) {
26
26
  var _a, _b, _c, _d, _e, _f;
27
27
  var _g;
28
+ const cacheDirectoryPath = (0, path_1.resolve)(opts.rootDir || opts.cwd, opts.config.cacheDirectoryPath || 'node_modules/.cache');
28
29
  const enableMFSU = opts.config.mfsu !== false;
29
30
  let mfsu = null;
30
31
  if (enableMFSU) {
@@ -42,8 +43,7 @@ async function dev(opts) {
42
43
  },
43
44
  mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
44
45
  runtimePublicPath: opts.config.runtimePublicPath,
45
- tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
46
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules/.cache/mfsu'),
46
+ tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) || (0, path_1.join)(cacheDirectoryPath, 'mfsu'),
47
47
  onMFSUProgress: opts.onMFSUProgress,
48
48
  getCacheDependency() {
49
49
  return stripUndefined({
@@ -80,7 +80,12 @@ async function dev(opts) {
80
80
  modifyWebpackConfig: opts.modifyWebpackConfig,
81
81
  hmr: process.env.HMR !== 'none',
82
82
  analyze: process.env.ANALYZE,
83
- cache: opts.cache,
83
+ cache: opts.cache
84
+ ? {
85
+ ...opts.cache,
86
+ cacheDirectory: (0, path_1.join)(cacheDirectoryPath, 'bundler-webpack'),
87
+ }
88
+ : undefined,
84
89
  });
85
90
  const depConfig = await (0, config_1.getConfig)({
86
91
  cwd: opts.cwd,
@@ -94,7 +99,7 @@ async function dev(opts) {
94
99
  chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
95
100
  cache: {
96
101
  buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
97
- cacheDirectory: (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
102
+ cacheDirectory: (0, path_1.join)(cacheDirectoryPath, 'mfsu-deps'),
98
103
  },
99
104
  });
100
105
  (_g = webpackConfig.resolve).alias || (_g.alias = {});
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as parcelCSS from '@parcel/css';
2
1
  import type webpack from '../compiled/webpack';
3
2
  import './requireHook';
4
3
  export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
@@ -7,5 +6,4 @@ export * from './build';
7
6
  export * from './config/config';
8
7
  export * from './dev';
9
8
  export * from './schema';
10
- export { parcelCSS };
11
9
  export { webpack };
package/dist/index.js CHANGED
@@ -10,25 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
15
  };
28
16
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.parcelCSS = void 0;
30
- const parcelCSS = __importStar(require("@parcel/css"));
31
- exports.parcelCSS = parcelCSS;
32
17
  require("./requireHook");
33
18
  __exportStar(require("./build"), exports);
34
19
  __exportStar(require("./config/config"), exports);
@@ -0,0 +1,2 @@
1
+ import * as parcelCSS from '@parcel/css';
2
+ export { parcelCSS };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parcelCSS = void 0;
27
+ const parcelCSS = __importStar(require("@parcel/css"));
28
+ exports.parcelCSS = parcelCSS;
package/dist/schema.js CHANGED
@@ -37,6 +37,7 @@ function getSchemas() {
37
37
  alias: (Joi) => Joi.object(),
38
38
  autoCSSModules: (Joi) => Joi.boolean(),
39
39
  autoprefixer: (Joi) => Joi.object(),
40
+ cacheDirectoryPath: (Joi) => Joi.string(),
40
41
  chainWebpack: (Joi) => Joi.function(),
41
42
  copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
42
43
  from: Joi.string(),
@@ -27,21 +27,21 @@ async function createServer(opts) {
27
27
  }));
28
28
  // compression
29
29
  app.use(require('@umijs/bundler-webpack/compiled/compression')());
30
- // TODO: headers
31
- // before middlewares
32
- (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
33
- // TODO: add to before middleware
30
+ // debug all js file
34
31
  app.use((req, res, next) => {
35
32
  const file = req.path;
36
33
  const filePath = (0, path_1.join)(opts.cwd, file);
37
34
  const ext = (0, path_1.extname)(filePath);
38
35
  if (ext === '.js' && (0, fs_1.existsSync)(filePath)) {
36
+ utils_1.logger.info('[dev]', `${file} is responded with ${filePath}, remove it to use original file`);
39
37
  res.sendFile(filePath);
40
38
  }
41
39
  else {
42
40
  next();
43
41
  }
44
42
  });
43
+ // before middlewares
44
+ (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
45
45
  // webpack dev middleware
46
46
  const configs = Array.isArray(webpackConfig)
47
47
  ? webpackConfig
@@ -188,7 +188,7 @@ async function createServer(opts) {
188
188
  const protocol = userConfig.https ? 'https:' : 'http:';
189
189
  const port = opts.port || 8000;
190
190
  server.listen(port, () => {
191
- const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
191
+ const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : 'localhost';
192
192
  utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
193
193
  });
194
194
  return server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.4",
3
+ "version": "4.0.7",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -35,10 +35,10 @@
35
35
  "@svgr/plugin-jsx": "^6.2.1",
36
36
  "@svgr/plugin-svgo": "^6.2.0",
37
37
  "@types/hapi__joi": "17.1.8",
38
- "@umijs/babel-preset-umi": "4.0.4",
39
- "@umijs/bundler-utils": "4.0.4",
40
- "@umijs/mfsu": "4.0.4",
41
- "@umijs/utils": "4.0.4",
38
+ "@umijs/babel-preset-umi": "4.0.7",
39
+ "@umijs/bundler-utils": "4.0.7",
40
+ "@umijs/mfsu": "4.0.7",
41
+ "@umijs/utils": "4.0.7",
42
42
  "cors": "^2.8.5",
43
43
  "css-loader": "6.7.1",
44
44
  "es5-imcompatible-versions": "^0.1.73",