@easyv/react-component-builder 0.23.3 → 0.25.0-beta.1

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.
@@ -10,31 +10,46 @@ if (fs.existsSync(webpackConfigExtend)) {
10
10
  webpackConfigExtendFn = require(webpackConfigExtend);
11
11
  }
12
12
 
13
- process.env.NODE_ENV = 'production';
14
-
15
13
  module.exports = (
16
14
  { filename, module_name, version },
17
- { uniqueId, removeConsole },
15
+ { uniqueId, removeConsole, format = 'amd' },
18
16
  ) => {
17
+ // launcher/start.js loads the dev config, which sets NODE_ENV=development.
18
+ // babel-preset-react-app reads BABEL_ENV first, so pin both before compile.
19
+ process.env.BABEL_ENV = 'production';
20
+ process.env.NODE_ENV = 'production';
21
+
19
22
  const entry = path.resolve(appComponents, filename, 'index');
23
+ const isEsm = format === 'esm';
20
24
  const cf = {
21
25
  ...commonConfig({ isProduction: true, uniqueId, entrys: [entry] }),
22
- mode: process.env.NODE_ENV,
26
+ mode: 'production',
23
27
  entry,
24
28
  output: {
25
29
  path: appBuild,
26
30
  filename: `${module_name}.${version}.js`,
27
- library: `${module_name}@${version}`,
28
- libraryTarget: 'amd',
31
+ pathinfo: false,
32
+ library: isEsm
33
+ ? { type: 'module' }
34
+ : { name: `${module_name}@${version}`, type: 'amd' },
29
35
  },
30
- externals: [
31
- 'react',
32
- 'react-dom',
33
- 'three',
34
- 'lodash',
35
- 'd3',
36
- '@material-ui/styles',
37
- ],
36
+ externals: isEsm
37
+ ? {
38
+ react: 'react',
39
+ 'react-dom': 'react-dom',
40
+ three: 'three',
41
+ lodash: 'lodash',
42
+ d3: 'd3',
43
+ '@material-ui/styles': '@material-ui/styles',
44
+ }
45
+ : [
46
+ 'react',
47
+ 'react-dom',
48
+ 'three',
49
+ 'lodash',
50
+ 'd3',
51
+ '@material-ui/styles',
52
+ ],
38
53
  devtool: false,
39
54
  plugins: [
40
55
  new webpack.ProvidePlugin({
@@ -43,27 +58,36 @@ module.exports = (
43
58
  ReactDom: 'react-dom',
44
59
  }),
45
60
  ],
46
- };
47
-
48
- if (webpackConfigExtendFn) {
49
- return webpackConfigExtendFn(cf, {
50
- production: true,
51
- });
52
- }
53
-
54
- if (removeConsole) {
55
- cf['optimization'] = {
61
+ optimization: {
62
+ minimize: true,
63
+ concatenateModules: true,
56
64
  minimizer: [
57
65
  new TerserWebpackPlugin({
58
66
  parallel: true,
67
+ extractComments: false,
59
68
  terserOptions: {
60
69
  compress: {
61
- drop_console: true,
70
+ drop_console: !!removeConsole,
71
+ passes: 2,
72
+ },
73
+ format: {
74
+ comments: false,
62
75
  },
63
76
  },
64
77
  }),
65
78
  ],
66
- };
79
+ },
80
+ };
81
+
82
+ if (isEsm) {
83
+ cf.experiments = { outputModule: true };
84
+ cf.externalsType = 'module';
85
+ }
86
+
87
+ if (webpackConfigExtendFn) {
88
+ return webpackConfigExtendFn(cf, {
89
+ production: true,
90
+ });
67
91
  }
68
92
 
69
93
  return cf;
@@ -1,5 +1,26 @@
1
1
  const { appSrc, ownLoaders, cliNodeModules } = require("../config/paths");
2
2
 
3
+ function styleUse(isProduction, cssLoaderOptions, extraLoaders) {
4
+ const cssOptions = { esModule: true };
5
+ if (isProduction) cssOptions.sourceMap = false;
6
+ if (cssLoaderOptions) Object.assign(cssOptions, cssLoaderOptions);
7
+
8
+ const loaders = [
9
+ {
10
+ loader: isProduction ? "mini-style-loader" : "style-loader",
11
+ },
12
+ ];
13
+ if (isProduction) {
14
+ loaders.push({ loader: "mini-css-runtime-loader" });
15
+ }
16
+ loaders.push({
17
+ loader: "css-loader",
18
+ options: cssOptions,
19
+ });
20
+ if (extraLoaders) loaders.push.apply(loaders, extraLoaders);
21
+ return loaders;
22
+ }
23
+
3
24
  module.exports = function ({ isProduction, uniqueId, entrys }) {
4
25
  return {
5
26
  stats: "errors-only",
@@ -54,9 +75,7 @@ module.exports = function ({ isProduction, uniqueId, entrys }) {
54
75
 
55
76
  {
56
77
  test: /\.js\.map$/,
57
- use: {
58
- loader: "file-loader",
59
- },
78
+ type: "asset/resource",
60
79
  },
61
80
 
62
81
  {
@@ -64,51 +83,41 @@ module.exports = function ({ isProduction, uniqueId, entrys }) {
64
83
  oneOf: [
65
84
  {
66
85
  test: /\.(M|m)odule\.css$/,
67
- use: [
68
- {
69
- loader: "style-loader",
70
- },
71
- {
72
- loader: "css-loader",
73
- options: {
74
- modules: {
75
- localIdentName: isProduction
76
- ? "[name]_[local]_[hash:base64:5]"
77
- : "[path][name]__[local]",
78
- },
79
- },
86
+ use: styleUse(isProduction, {
87
+ modules: {
88
+ localIdentName: isProduction
89
+ ? "[name]_[local]_[hash:base64:5]"
90
+ : "[path][name]__[local]",
80
91
  },
81
- ],
92
+ }),
82
93
  },
83
94
  {
84
- use: ["style-loader", "css-loader"],
95
+ use: styleUse(isProduction),
85
96
  },
86
97
  ],
87
98
  },
88
99
  {
89
100
  test: /\.less$/,
90
101
  include: [appSrc],
91
- use: [
102
+ use: styleUse(
103
+ isProduction,
92
104
  {
93
- loader: "style-loader",
105
+ modules: true,
94
106
  },
95
- {
96
- loader: "css-loader",
97
- options: {
98
- modules: true,
107
+ [
108
+ {
109
+ loader: "less-loader",
99
110
  },
100
- },
101
- {
102
- loader: "less-loader",
103
- },
104
- ],
111
+ ]
112
+ ),
105
113
  },
106
114
  {
107
- // exclude: /node_modules/,
108
115
  test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
109
- loader: "url-loader",
110
- options: {
111
- limit: 20 * 1024 * 1024,
116
+ type: "asset",
117
+ parser: {
118
+ dataUrlCondition: {
119
+ maxSize: 20 * 1024 * 1024,
120
+ },
112
121
  },
113
122
  },
114
123
  ].filter(Boolean),
@@ -34,8 +34,7 @@ module.exports = ({ port, modules }) => {
34
34
  output: {
35
35
  filename: '[name].js',
36
36
  globalObject: 'this',
37
- libraryTarget: 'var',
38
- library: '__MAIN__', // 暴露到window上的属性名称
37
+ library: { name: '__MAIN__', type: 'var' }, // 暴露到window上的属性名称
39
38
  },
40
39
  devtool: 'source-map',
41
40
  plugins: [
@@ -75,7 +74,7 @@ module.exports = ({ port, modules }) => {
75
74
  client: {
76
75
  logging: 'warn',
77
76
  },
78
- onBeforeSetupMiddleware: function (devServer) {
77
+ setupMiddlewares: (middlewares, devServer) => {
79
78
  if (!devServer) {
80
79
  throw new Error('webpack-dev-server is not defined');
81
80
  }
@@ -118,6 +117,7 @@ module.exports = ({ port, modules }) => {
118
117
  res.send(data);
119
118
  });
120
119
  });
120
+ return middlewares;
121
121
  },
122
122
  },
123
123
  };
package/launcher/build.js CHANGED
@@ -18,7 +18,13 @@ function canReadAsset(asset) {
18
18
  }
19
19
 
20
20
  module.exports = (name, option = {}) => {
21
- const { unique = true, removeConsole } = option;
21
+ process.env.BABEL_ENV = 'production';
22
+ process.env.NODE_ENV = 'production';
23
+ const { unique = true, removeConsole, format = 'amd' } = option;
24
+ if (format !== 'amd' && format !== 'esm') {
25
+ console.log(chalk.red(`不支持的打包格式 "${format}",可选:amd、esm`));
26
+ process.exit(1);
27
+ }
22
28
  return new Promise(async (resolve, reject) => {
23
29
  // 检查组件是否存在
24
30
  // 开始打包
@@ -53,10 +59,10 @@ module.exports = (name, option = {}) => {
53
59
  base.filename = `${componentInfo.dirname}`;
54
60
  base.module_name = `${base.module_name}${unique ? '.' + easyvcid : ''}`;
55
61
  const compiler = webpack(
56
- getWebpackConfig(base, { uniqueId: easyvcid, removeConsole }),
62
+ getWebpackConfig(base, { uniqueId: easyvcid, removeConsole, format }),
57
63
  );
58
64
 
59
- console.log('Creating an optimized production build...');
65
+ console.log(`Creating an optimized production build (${format})...`);
60
66
 
61
67
  compiler.run((err, stats) => {
62
68
  const message = stats.toJson({
@@ -110,8 +116,10 @@ module.exports = (name, option = {}) => {
110
116
 
111
117
  console.log();
112
118
  }
119
+ const mainAsset = message.assetsByChunkName.main;
120
+ const mainFile = Array.isArray(mainAsset) ? mainAsset[0] : mainAsset;
113
121
  resolve({
114
- file: path.join(message.outputPath, message.assetsByChunkName.main),
122
+ file: path.join(message.outputPath, mainFile),
115
123
  base,
116
124
  sourcePath: sourcePath,
117
125
  });
package/launcher/start.js CHANGED
@@ -124,9 +124,10 @@ function start({ port, modules }) {
124
124
  },
125
125
  });
126
126
 
127
- const server = new WebpackDevServer(compiler, config.devServer);
127
+ const devServerOptions = { ...config.devServer, host: HOST };
128
+ const server = new WebpackDevServer(devServerOptions, compiler);
128
129
 
129
- server.listen(port, HOST, (err) => {
130
+ server.startCallback((err) => {
130
131
  if (err) {
131
132
  return console.log(err);
132
133
  }
@@ -140,8 +141,7 @@ function start({ port, modules }) {
140
141
 
141
142
  ['SIGINT', 'SIGTERM'].forEach(function (sig) {
142
143
  process.on(sig, function () {
143
- server.close();
144
- process.exit();
144
+ server.stopCallback(() => process.exit());
145
145
  });
146
146
  });
147
147
  }
@@ -0,0 +1,56 @@
1
+ const crypto = require('crypto');
2
+
3
+ function shortId(file) {
4
+ return crypto
5
+ .createHash('sha1')
6
+ .update(file)
7
+ .digest('base64')
8
+ .replace(/[+/=]/g, '')
9
+ .slice(0, 8);
10
+ }
11
+
12
+ const TINY_LIST = `var ___CSS_LOADER_EXPORT___ = [];
13
+ ___CSS_LOADER_EXPORT___.toString = function () {
14
+ return this.map(function (item) {
15
+ return item[1];
16
+ }).join("");
17
+ };`;
18
+
19
+ // Rewrites css-loader output so style injection does not pull in
20
+ // css-loader/dist/runtime/api.js or noSourceMaps.js.
21
+ module.exports = function miniCssRuntimeLoader(source) {
22
+ if (!source.includes('___CSS_LOADER_API_IMPORT___')) return source;
23
+
24
+ if (/___CSS_LOADER_EXPORT___\.i\(/.test(source)) {
25
+ this.emitError(
26
+ new Error(
27
+ `CSS @import / composes is not supported in the production build: ${this.resourcePath}`,
28
+ ),
29
+ );
30
+ return source;
31
+ }
32
+
33
+ const moduleId = JSON.stringify(shortId(this.resourcePath || ''));
34
+ let code = source
35
+ .replace(/import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from [^;]+;\n?/g, '')
36
+ .replace(/import ___CSS_LOADER_API_SOURCEMAP_IMPORT___ from [^;]+;\n?/g, '')
37
+ .replace(/import ___CSS_LOADER_API_IMPORT___ from [^;]+;\n?/g, '')
38
+ .replace(
39
+ /var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___\(___CSS_LOADER_API_(?:NO_)?SOURCEMAP_IMPORT___\);/,
40
+ TINY_LIST,
41
+ )
42
+ .replace(
43
+ /___CSS_LOADER_EXPORT___\.push\(\[module\.id,/g,
44
+ `___CSS_LOADER_EXPORT___.push([${moduleId},`,
45
+ );
46
+
47
+ if (code.includes('___CSS_LOADER_API_') || code.includes('[module.id,')) {
48
+ this.emitError(
49
+ new Error(
50
+ `mini-css-runtime-loader failed to strip css-loader runtime: ${this.resourcePath}`,
51
+ ),
52
+ );
53
+ }
54
+
55
+ return code;
56
+ };
@@ -0,0 +1,19 @@
1
+ function pitch(request) {
2
+ const contentRequest = JSON.stringify(
3
+ this.utils.contextify(this.context, `!!${request}`),
4
+ );
5
+
6
+ return `
7
+ import content from ${contentRequest};
8
+ var css = content && content.toString ? content.toString() : "";
9
+ if (typeof document !== "undefined" && css) {
10
+ var style = document.createElement("style");
11
+ style.textContent = css;
12
+ document.head.appendChild(style);
13
+ }
14
+ export default content && content.locals;
15
+ `;
16
+ }
17
+
18
+ module.exports = function miniStyleLoader() {};
19
+ module.exports.pitch = pitch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-component-builder",
3
- "version": "0.23.3",
3
+ "version": "0.25.0-beta.1",
4
4
  "files": [
5
5
  "launcher",
6
6
  "templates",
@@ -17,7 +17,7 @@
17
17
  "postpublish": "sync-to-mirror"
18
18
  },
19
19
  "dependencies": {
20
- "@babel/core": "7.9.0",
20
+ "@babel/core": "^7.12.0",
21
21
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
22
22
  "@babel/register": "^7.10.4",
23
23
  "@easyv/react-gui": "3.1.0",
@@ -26,32 +26,28 @@
26
26
  "acorn": "^7.3.1",
27
27
  "acorn-jsx": "^5.2.0",
28
28
  "antd": "^4.0.3",
29
- "babel-loader": "8.1.0",
29
+ "babel-loader": "^9.2.0",
30
30
  "babel-plugin-named-asset-import": "^0.3.6",
31
31
  "babel-preset-react-app": "^10.0.1",
32
32
  "classnames": "^2.2.6",
33
- "css-loader": "3.4.2",
33
+ "css-loader": "^6.11.0",
34
34
  "d3": "^5.16.0",
35
- "expose-loader": "^1.0.0",
36
- "file-loader": "4.3.0",
35
+ "expose-loader": "^4.0.0",
37
36
  "filesize": "^6.1.0",
38
37
  "fs-extra": "^9.0.1",
39
38
  "glob": "^7.1.6",
40
- "html-webpack-plugin": "4.5.2",
39
+ "html-webpack-plugin": "^5.6.0",
41
40
  "inquirer": "^7.3.0",
42
- "less-loader": "^6.2.0",
41
+ "less-loader": "^11.1.0",
43
42
  "lodash": "^4.17.19",
44
43
  "multer": "^1.4.2",
45
- "optimize-css-assets-webpack-plugin": "6.0.1",
46
44
  "react": "^16.13.1",
47
45
  "react-dev-utils": "10.2.1",
48
46
  "react-dom": "^16.13.1",
49
- "style-loader": "0.23.1",
47
+ "style-loader": "^3.3.0",
50
48
  "three": "^0.100.0",
51
- "url-loader": "2.3.0",
52
- "webpack": "4.47.0",
53
- "webpack-dev-server": "4.15.1",
54
- "webpack-manifest-plugin": "4.1.1"
49
+ "webpack": "^5.96.0",
50
+ "webpack-dev-server": "^5.1.0"
55
51
  },
56
52
  "devDependencies": {
57
53
  "@easyv/sync-to-mirror": "^0.0.2",
@@ -59,7 +55,7 @@
59
55
  "@types/node": "^12.0.0",
60
56
  "@types/react": "^16.9.0",
61
57
  "@types/react-dom": "^16.9.0",
62
- "terser-webpack-plugin": "^4.2.3"
58
+ "terser-webpack-plugin": "^5.3.10"
63
59
  },
64
60
  "easyv": {
65
61
  "src": "examples",
@@ -69,9 +65,10 @@
69
65
  "online": "https://easyv.dtstack.com",
70
66
  "test": "http://172.16.10.70:1337"
71
67
  },
72
- "assets": "https://easyv-develop.oss-cn-hangzhou.aliyuncs.com/"
68
+ "assets": "https://dt-easyv-prod.oss-cn-hangzhou.aliyuncs.com/"
73
69
  },
74
70
  "publishConfig": {
75
- "registry": "https://registry.npmjs.org/"
71
+ "registry": "https://registry.npmjs.org/",
72
+ "access": "public"
76
73
  }
77
74
  }