@shuvi/toolpack 1.0.2 → 1.0.4

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.
@@ -37,7 +37,6 @@ const constants_1 = require("@shuvi/shared/lib/constants");
37
37
  const fix_watching_plugin_1 = __importDefault(require("../plugins/fix-watching-plugin"));
38
38
  const crypto = __importStar(require("crypto"));
39
39
  const jsconfig_paths_plugin_1 = __importDefault(require("../plugins/jsconfig-paths-plugin"));
40
- const helpers_1 = require("./parts/helpers");
41
40
  const resolveLocalLoader = (name) => path.join(__dirname, `../loaders/${name}`);
42
41
  const terserOptions = {
43
42
  parse: {
@@ -96,27 +95,13 @@ function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot,
96
95
  emitOnErrors: !dev,
97
96
  checkWasmTypes: false,
98
97
  nodeEnv: false,
98
+ splitChunks: false,
99
99
  runtimeChunk: undefined,
100
100
  minimize: !dev,
101
101
  realContentHash: false
102
102
  });
103
103
  if (dev) {
104
104
  config.optimization.usedExports(false);
105
- config.optimization.splitChunks({
106
- chunks: helpers_1.splitChunksFilter,
107
- cacheGroups: {
108
- defaultVendors: false,
109
- default: false,
110
- vendors: {
111
- name: 'vendors',
112
- filename: (0, helpers_1.commonChunkFilename)({ dev: true }),
113
- test: /[\\/]node_modules[\\/]/,
114
- // Don't let webpack eliminate this chunk (prevents this chunk from
115
- // becoming a part of the commons chunk)
116
- enforce: true
117
- }
118
- }
119
- });
120
105
  }
121
106
  else {
122
107
  // @ts-ignore
@@ -1,7 +1,5 @@
1
- import { IWebpackHelpers } from '../types';
2
1
  import { WebpackChain, BaseOptions } from './base';
3
2
  export interface BrowserOptions extends BaseOptions {
4
- webpackHelpers: IWebpackHelpers;
5
3
  analyze?: boolean;
6
4
  }
7
5
  export declare function createBrowserWebpackChain(options: BrowserOptions): WebpackChain;
@@ -1,6 +1,2 @@
1
1
  import { WebpackChain, BaseOptions } from './base';
2
- import { IWebpackHelpers } from '../types';
3
- export interface NodeOptions extends BaseOptions {
4
- webpackHelpers: IWebpackHelpers;
5
- }
6
- export declare function createNodeWebpackChain(options: NodeOptions): WebpackChain;
2
+ export declare function createNodeWebpackChain(options: BaseOptions): WebpackChain;
@@ -4,8 +4,9 @@ exports.createNodeWebpackChain = void 0;
4
4
  const base_1 = require("./base");
5
5
  const external_1 = require("./parts/external");
6
6
  const style_1 = require("./parts/style");
7
+ const helpers_1 = require("./parts/helpers");
7
8
  function createNodeWebpackChain(options) {
8
- const { webpackHelpers, dev } = options;
9
+ const { dev } = options;
9
10
  const chain = (0, base_1.baseWebpackChain)(options);
10
11
  chain.target('node');
11
12
  chain.devtool(dev ? 'cheap-module-source-map' : false);
@@ -23,7 +24,7 @@ function createNodeWebpackChain(options) {
23
24
  chain.resolve.mainFields.clear().add('main').add('module');
24
25
  chain.output.libraryTarget('commonjs2');
25
26
  chain.optimization.minimize(false);
26
- webpackHelpers.addExternals(chain, (0, external_1.nodeExternals)({
27
+ (0, helpers_1.addExternals)(chain, (0, external_1.nodeExternals)({
27
28
  projectRoot: options.projectRoot,
28
29
  include: options.include
29
30
  }));
@@ -1,5 +1,7 @@
1
- import { IWebpackHelpers } from '../../types';
2
- export declare const webpackHelpers: () => IWebpackHelpers;
1
+ import { WebpackChain } from '../base';
2
+ import { ExternalsFunction } from '../../types';
3
+ export declare const checkWebpackExternals: (webpackChain: WebpackChain) => void;
4
+ export declare const addExternals: (webpackChain: WebpackChain, externalFn: ExternalsFunction) => void;
3
5
  export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
4
6
  export declare function splitChunksFilter(chunk: any): boolean;
5
7
  export declare const commonChunkFilename: ({ dev }: {
@@ -1,7 +1,19 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commonChunkFilename = exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.webpackHelpers = void 0;
4
- const webpackHelpers = () => {
6
+ exports.commonChunkFilename = exports.splitChunksFilter = exports.shouldUseRelativeAssetPaths = exports.addExternals = exports.checkWebpackExternals = void 0;
7
+ const invariant_1 = __importDefault(require("@shuvi/utils/lib/invariant"));
8
+ const externalsFunctionMap = new WeakMap();
9
+ const checkWebpackExternals = (webpackChain) => {
10
+ let externals = webpackChain.get('externals');
11
+ (0, invariant_1.default)(!externals ||
12
+ (typeof externals === 'function' &&
13
+ externals.name === 'defaultExternalsFn'), `Externals was modified directly, addExternals will have no effect.`);
14
+ };
15
+ exports.checkWebpackExternals = checkWebpackExternals;
16
+ const initExternalsHelpers = (webpackChain) => {
5
17
  const externalFns = [];
6
18
  const defaultExternalsFn = ({ context, request }, callback) => {
7
19
  let callbackCalled = false;
@@ -27,23 +39,26 @@ const webpackHelpers = () => {
27
39
  callback(null, undefined);
28
40
  }
29
41
  };
30
- return {
31
- addExternals: (webpackChain, externalFn) => {
32
- let externals = webpackChain.get('externals');
33
- if (!externals) {
34
- externals = defaultExternalsFn;
35
- webpackChain.externals(externals);
36
- }
37
- if (typeof externals === 'function' &&
38
- externals.name === 'defaultExternalsFn') {
39
- externalFns.push(externalFn);
40
- return;
41
- }
42
- throw new Error('Externals was modified directly, addExternals will have no effect.');
43
- }
44
- };
42
+ let externals = webpackChain.get('externals');
43
+ (0, invariant_1.default)(!externals, `webpackChain externals has been set, initWebpackHelpers can't work as expected.`);
44
+ if (!externals) {
45
+ externals = defaultExternalsFn;
46
+ webpackChain.externals(externals);
47
+ externalsFunctionMap.set(webpackChain, externalFns);
48
+ }
49
+ };
50
+ const addExternals = (webpackChain, externalFn) => {
51
+ let externals = webpackChain.get('externals');
52
+ if (!externals) {
53
+ initExternalsHelpers(webpackChain);
54
+ }
55
+ else {
56
+ (0, exports.checkWebpackExternals)(webpackChain);
57
+ }
58
+ const externalFns = externalsFunctionMap.get(webpackChain);
59
+ externalFns.push(externalFn);
45
60
  };
46
- exports.webpackHelpers = webpackHelpers;
61
+ exports.addExternals = addExternals;
47
62
  function shouldUseRelativeAssetPaths(publicPath) {
48
63
  return publicPath === './';
49
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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.2",
23
+ "@shuvi/compiler": "1.0.4",
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
  "lightningcss": "1.15.0",
38
- "@shuvi/shared": "1.0.2",
39
- "@shuvi/utils": "1.0.2",
38
+ "@shuvi/shared": "1.0.4",
39
+ "@shuvi/utils": "1.0.4",
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",