@shuvi/toolpack 1.0.20 → 1.0.22

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.
@@ -21,6 +21,7 @@ export interface BaseOptions {
21
21
  };
22
22
  lightningCss?: boolean;
23
23
  compiler?: CompilerOptions;
24
+ analyze?: boolean;
24
25
  }
25
26
  export { WebpackChain };
26
27
  export declare function getDefineEnv(env: {
@@ -28,4 +29,4 @@ export declare function getDefineEnv(env: {
28
29
  }): {
29
30
  [x: string]: string;
30
31
  };
31
- export declare function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, jsConfig, name, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
32
+ export declare function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, jsConfig, name, publicPath, env, cacheDir, analyze }: BaseOptions): WebpackChain;
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.baseWebpackChain = exports.getDefineEnv = exports.WebpackChain = void 0;
30
30
  const webpack_chain_1 = __importDefault(require("webpack-chain"));
31
31
  exports.WebpackChain = webpack_chain_1.default;
32
+ const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
32
33
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
33
34
  const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
34
35
  const webpack_1 = __importDefault(require("webpack"));
@@ -71,7 +72,9 @@ function getDefineEnv(env) {
71
72
  }, {}));
72
73
  }
73
74
  exports.getDefineEnv = getDefineEnv;
74
- function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, jsConfig, name, publicPath = '/', env = {}, cacheDir }) {
75
+ /** remove 'shuvi/' of the target name */
76
+ const getSimplifiedTargetName = (targetName) => targetName.replace(/^shuvi\//, '');
77
+ function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot, include, jsConfig, name, publicPath = '/', env = {}, cacheDir, analyze }) {
75
78
  const config = new webpack_chain_1.default();
76
79
  config.mode(dev ? 'development' : 'production');
77
80
  config.bail(!dev);
@@ -120,6 +123,21 @@ function baseWebpackChain({ dev, outputDir, lightningCss, compiler, projectRoot,
120
123
  : css_minimizer_webpack_plugin_1.default.cssnanoMinify
121
124
  }
122
125
  ]);
126
+ if (analyze) {
127
+ const targetName = getSimplifiedTargetName(name);
128
+ config
129
+ .plugin('private/bundle-analyzer-plugin')
130
+ .use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
131
+ {
132
+ logLevel: 'warn',
133
+ openAnalyzer: false,
134
+ analyzerMode: 'static',
135
+ reportFilename: `../analyze/${targetName}.html`,
136
+ generateStatsFile: true,
137
+ statsFilename: `../analyze/${targetName}-stats.json`
138
+ }
139
+ ]);
140
+ }
123
141
  }
124
142
  // Support for NODE_PATH
125
143
  const nodePathList = (process.env.NODE_PATH || '')
@@ -1,5 +1,2 @@
1
1
  import { WebpackChain, BaseOptions } from './base';
2
- export interface BrowserOptions extends BaseOptions {
3
- analyze?: boolean;
4
- }
5
- export declare function createBrowserWebpackChain(options: BrowserOptions): WebpackChain;
2
+ export declare function createBrowserWebpackChain(options: BaseOptions): WebpackChain;
@@ -30,7 +30,6 @@ exports.createBrowserWebpackChain = void 0;
30
30
  const crypto = __importStar(require("crypto"));
31
31
  const webpack_1 = __importDefault(require("webpack"));
32
32
  const path = __importStar(require("path"));
33
- const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
34
33
  const resolve_1 = require("@shuvi/utils/resolve");
35
34
  const base_1 = require("./base");
36
35
  const style_1 = require("./parts/style");
@@ -50,7 +49,7 @@ const FRAMEWORK_REACT_MODULES = [
50
49
  }
51
50
  ];
52
51
  function createBrowserWebpackChain(options) {
53
- const { projectRoot, cacheDir, jsConfig, dev, publicPath, analyze } = options;
52
+ const { projectRoot, cacheDir, jsConfig, dev, publicPath } = options;
54
53
  const chain = (0, base_1.baseWebpackChain)(options);
55
54
  const useTypeScript = !!(jsConfig === null || jsConfig === void 0 ? void 0 : jsConfig.useTypeScript);
56
55
  chain.target('web');
@@ -169,16 +168,6 @@ function createBrowserWebpackChain(options) {
169
168
  maxInitialRequests: 25,
170
169
  minSize: 20000
171
170
  });
172
- if (analyze) {
173
- chain.plugin('private/bundle-analyzer-plugin').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
174
- {
175
- logLevel: 'warn',
176
- openAnalyzer: false,
177
- analyzerMode: 'static',
178
- reportFilename: '../analyze/client.html'
179
- }
180
- ]);
181
- }
182
171
  }
183
172
  // node polyfills
184
173
  chain.resolve.set('fallback', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -20,7 +20,7 @@
20
20
  "node": ">= 16.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@shuvi/compiler": "1.0.20",
23
+ "@shuvi/compiler": "1.0.22",
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.19.0",
38
- "@shuvi/shared": "1.0.20",
39
- "@shuvi/utils": "1.0.20",
38
+ "@shuvi/shared": "1.0.22",
39
+ "@shuvi/utils": "1.0.22",
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",