@shuvi/toolpack 1.0.0-rc.12 → 1.0.0-rc.13

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.
@@ -1,2 +1 @@
1
1
  export declare const AppSourceRegexs: RegExp[];
2
- export declare const CommonChunkFilename = "static/common/[name].js";
package/lib/constants.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommonChunkFilename = exports.AppSourceRegexs = void 0;
3
+ exports.AppSourceRegexs = void 0;
4
4
  exports.AppSourceRegexs = [
5
5
  /([/\\]shuvi-app[/\\])|([/\\]\.shuvi[/\\])/
6
6
  ];
7
- exports.CommonChunkFilename = 'static/common/[name].js';
@@ -75,7 +75,7 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
75
75
  // This saves chunks with the name given via `import()`
76
76
  chunkFilename: `static/chunks/${dev ? '[name]' : '[name].[contenthash:8]'}.js`,
77
77
  hotUpdateChunkFilename: 'static/webpack/[id].[fullhash].hot-update.js',
78
- hotUpdateMainFilename: 'static/webpack/[fullhash].hot-update.json',
78
+ hotUpdateMainFilename: 'static/webpack/[runtime].[fullhash].hot-update.json',
79
79
  strictModuleExceptionHandling: true,
80
80
  // crossOriginLoading: crossOrigin,
81
81
  webassemblyModuleFilename: 'static/wasm/[modulehash:8].wasm',
@@ -99,7 +99,7 @@ function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, p
99
99
  default: false,
100
100
  vendors: {
101
101
  name: 'vendors',
102
- filename: constants_2.CommonChunkFilename,
102
+ filename: (0, helpers_1.commonChunkFilename)({ dev: true }),
103
103
  test: /[\\/]node_modules[\\/]/,
104
104
  // Don't let webpack eliminate this chunk (prevents this chunk from
105
105
  // becoming a part of the commons chunk)
@@ -32,7 +32,6 @@ const webpack_1 = __importDefault(require("webpack"));
32
32
  const path = __importStar(require("path"));
33
33
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
34
34
  const resolve_1 = require("@shuvi/utils/lib/resolve");
35
- const constants_1 = require("../../constants");
36
35
  const base_1 = require("./base");
37
36
  const style_1 = require("./parts/style");
38
37
  const helpers_1 = require("./parts/helpers");
@@ -105,8 +104,8 @@ function createBrowserWebpackChain(options) {
105
104
  framework: {
106
105
  chunks: 'all',
107
106
  name: 'framework',
108
- filename: constants_1.CommonChunkFilename,
109
- test(module) {
107
+ filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
108
+ test(module, { moduleGraph }) {
110
109
  const resource = module.nameForCondition();
111
110
  if (!resource) {
112
111
  return false;
@@ -122,9 +121,13 @@ function createBrowserWebpackChain(options) {
122
121
  // bundled with their issuer.
123
122
  // https://github.com/zeit/next.js/pull/9012
124
123
  if (frameworkModule.issuers) {
125
- for (const issuer of frameworkModule.issuers) {
126
- const issuerResource = module.issuer.nameForCondition();
127
- if (!issuer.test(issuerResource)) {
124
+ for (const issuerTest of frameworkModule.issuers) {
125
+ // fix: DeprecationWarning: Module.issuer: Use new ModuleGraph API
126
+ const issuer = moduleGraph.getIssuer(module);
127
+ const issuerResource = issuer
128
+ ? issuer.nameForCondition()
129
+ : null;
130
+ if (!issuerResource || !issuerTest.test(issuerResource)) {
128
131
  return false;
129
132
  }
130
133
  }
@@ -156,7 +159,7 @@ function createBrowserWebpackChain(options) {
156
159
  }
157
160
  return hash.digest('hex').substring(0, 8);
158
161
  },
159
- filename: constants_1.CommonChunkFilename,
162
+ filename: (0, helpers_1.commonChunkFilename)({ dev: false }),
160
163
  priority: 30,
161
164
  minChunks: 1,
162
165
  reuseExistingChunk: true
@@ -2,3 +2,6 @@ import { IWebpackHelpers } from '../../types';
2
2
  export declare const webpackHelpers: () => IWebpackHelpers;
3
3
  export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
4
4
  export declare function splitChunksFilter(chunk: any): boolean;
5
+ export declare const commonChunkFilename: ({ dev }: {
6
+ dev: boolean;
7
+ }) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
3
+ exports.commonChunkFilename = exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
4
4
  const webpackHelpers = () => {
5
5
  const externalFns = [];
6
6
  const defaultExternalsFn = ({ context, request }, callback) => {
@@ -50,8 +50,12 @@ function shouldUseRelativeAssetPaths(publicPath) {
50
50
  exports.shouldUseRelativeAssetPaths = shouldUseRelativeAssetPaths;
51
51
  function splitChunksFilter(chunk) {
52
52
  const excludes = {
53
- 'static/polyfill': true
53
+ // 'static/polyfill': true
54
54
  };
55
55
  return excludes[chunk.name] !== true;
56
56
  }
57
57
  exports.splitChunksFilter = splitChunksFilter;
58
+ const commonChunkFilename = ({ dev }) => {
59
+ return `static/common/${dev ? '[name]' : '[name].[contenthash:8]'}.js`;
60
+ };
61
+ exports.commonChunkFilename = commonChunkFilename;
@@ -1,11 +1,35 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const webpack_1 = __importDefault(require("webpack"));
29
+ const webpack_1 = __importStar(require("webpack"));
7
30
  const Entrypoint_1 = __importDefault(require("webpack/lib/Entrypoint"));
8
- const { RawSource } = webpack_1.default.sources;
31
+ const constants_1 = require("@shuvi/shared/lib/constants");
32
+ const { RawSource } = webpack_1.sources;
9
33
  const defaultOptions = {
10
34
  filename: 'build-manifest.json',
11
35
  modules: false,
@@ -63,6 +87,16 @@ class BuildManifestPlugin {
63
87
  }
64
88
  this._collect(chunkGroup, compiler, compilation, chunkRootModulesMap);
65
89
  });
90
+ const compilationAssets = compilation.getAssets();
91
+ this._manifest.polyfillFiles = compilationAssets
92
+ .filter(p => {
93
+ // Ensure only .js files are passed through
94
+ if (!p.name.endsWith('.js')) {
95
+ return false;
96
+ }
97
+ return p.info && constants_1.BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL in p.info;
98
+ })
99
+ .map(v => v.name);
66
100
  this._manifest.loadble = Object.keys(this._manifest.loadble)
67
101
  .sort()
68
102
  // eslint-disable-next-line no-sequences
@@ -0,0 +1,14 @@
1
+ import { Compiler } from 'webpack';
2
+ export declare class CopyFilePlugin {
3
+ private filePath;
4
+ private name;
5
+ private cacheKey;
6
+ private info?;
7
+ constructor({ filePath, cacheKey, name, info }: {
8
+ filePath: string;
9
+ cacheKey: string;
10
+ name: string;
11
+ info?: object;
12
+ });
13
+ apply(compiler: Compiler): void;
14
+ }
@@ -0,0 +1,87 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.CopyFilePlugin = void 0;
36
+ const fs_1 = require("fs");
37
+ const webpack_1 = require("webpack");
38
+ const loaderUtils = __importStar(require("loader-utils"));
39
+ const PLUGIN_NAME = 'CopyFilePlugin';
40
+ class CopyFilePlugin {
41
+ constructor({ filePath, cacheKey, name, info }) {
42
+ this.filePath = filePath;
43
+ this.cacheKey = cacheKey;
44
+ this.name = name;
45
+ this.info = info;
46
+ }
47
+ apply(compiler) {
48
+ // compiler.options.output.filename
49
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
50
+ const cache = compilation.getCache('CopyFilePlugin');
51
+ const hook = compilation.hooks.processAssets;
52
+ hook.tapPromise({
53
+ name: PLUGIN_NAME,
54
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
55
+ }, () => __awaiter(this, void 0, void 0, function* () {
56
+ if (cache) {
57
+ const cachedResult = yield cache.getPromise(this.filePath, this.cacheKey);
58
+ if (cachedResult) {
59
+ const { file, source } = cachedResult;
60
+ compilation.emitAsset(file, source, Object.assign({}, this.info));
61
+ return;
62
+ }
63
+ }
64
+ const content = yield fs_1.promises.readFile(this.filePath, 'utf8');
65
+ const hash = loaderUtils.interpolateName({
66
+ // we only care about hash, so use a fake path is ok
67
+ resourcePath: '/fake/path'
68
+ }, '[hash:8]', {
69
+ content
70
+ });
71
+ const file = compilation.getAssetPath(compiler.options.output.filename || this.name, {
72
+ contentHash: hash,
73
+ chunk: { id: this.name, name: this.name }
74
+ });
75
+ const source = new webpack_1.sources.RawSource(content);
76
+ if (cache) {
77
+ yield cache.storePromise(this.filePath, this.cacheKey, {
78
+ file,
79
+ source
80
+ });
81
+ }
82
+ compilation.emitAsset(file, source, Object.assign({}, this.info));
83
+ }));
84
+ });
85
+ }
86
+ }
87
+ exports.CopyFilePlugin = CopyFilePlugin;
@@ -18,6 +18,7 @@ export interface IChunk {
18
18
  request: string;
19
19
  }
20
20
  export interface IManifest {
21
+ polyfillFiles?: string[];
21
22
  entries: {
22
23
  [s: string]: IAssetMap;
23
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "1.0.0-rc.12",
3
+ "version": "1.0.0-rc.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -20,7 +20,7 @@
20
20
  "node": ">= 12.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@shuvi/compiler": "1.0.0-rc.12",
23
+ "@shuvi/compiler": "1.0.0-rc.13",
24
24
  "@babel/core": "7.12.10",
25
25
  "@babel/plugin-proposal-class-properties": "7.12.1",
26
26
  "@babel/plugin-proposal-nullish-coalescing-operator": "7.10.1",
@@ -35,8 +35,8 @@
35
35
  "@babel/preset-typescript": "7.12.7",
36
36
  "@babel/runtime": "7.12.5",
37
37
  "@parcel/css": "1.2.0",
38
- "@shuvi/shared": "1.0.0-rc.12",
39
- "@shuvi/utils": "1.0.0-rc.12",
38
+ "@shuvi/shared": "1.0.0-rc.13",
39
+ "@shuvi/utils": "1.0.0-rc.13",
40
40
  "babel-loader": "8.2.2",
41
41
  "babel-plugin-syntax-jsx": "6.18.0",
42
42
  "babel-plugin-transform-define": "2.0.0",
@@ -49,7 +49,7 @@
49
49
  "css-minimizer-webpack-plugin": "3.4.1",
50
50
  "es-module-lexer": "0.10.5",
51
51
  "esbuild": "0.14.38",
52
- "esbuild-loader": "^2.19.0",
52
+ "esbuild-loader": "2.19.0",
53
53
  "file-loader": "6.2.0",
54
54
  "fork-ts-checker-webpack-plugin": "6.0.8",
55
55
  "fs-extra": "9.0.1",
@@ -63,7 +63,7 @@
63
63
  "postcss-loader": "4.1.0",
64
64
  "postcss-preset-env": "6.7.0",
65
65
  "process": "0.11.10",
66
- "regenerator-runtime": "^0.13.9",
66
+ "regenerator-runtime": "0.13.9",
67
67
  "@swc/helpers": "0.4.3",
68
68
  "sass-loader": "10.1.0",
69
69
  "stream-browserify": "3.0.0",