@umijs/bundler-webpack 4.0.6 → 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) => {
@@ -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/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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.6",
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.6",
39
- "@umijs/bundler-utils": "4.0.6",
40
- "@umijs/mfsu": "4.0.6",
41
- "@umijs/utils": "4.0.6",
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",