@easyv/react-component-builder 0.14.1 → 0.16.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.
@@ -1,18 +1,22 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const commonConfig = require('./webpack.config.common');
4
- const { appComponents, appBuild, webpackConfigExtend } = require('./paths');
5
- const webpack = require('webpack');
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const TerserWebpackPlugin = require("terser-webpack-plugin");
4
+ const commonConfig = require("./webpack.config.common");
5
+ const { appComponents, appBuild, webpackConfigExtend } = require("./paths");
6
+ const webpack = require("webpack");
6
7
 
7
8
  let webpackConfigExtendFn;
8
9
  if (fs.existsSync(webpackConfigExtend)) {
9
10
  webpackConfigExtendFn = require(webpackConfigExtend);
10
11
  }
11
12
 
12
- process.env.NODE_ENV = 'production';
13
+ process.env.NODE_ENV = "production";
13
14
 
14
- module.exports = ({ filename, module_name, version }, { uniqueId }) => {
15
- const entry = path.resolve(appComponents, filename, 'index')
15
+ module.exports = (
16
+ { filename, module_name, version },
17
+ { uniqueId, removeConsole }
18
+ ) => {
19
+ const entry = path.resolve(appComponents, filename, "index");
16
20
  const cf = {
17
21
  ...commonConfig({ isProduction: true, uniqueId, entrys: [entry] }),
18
22
  mode: process.env.NODE_ENV,
@@ -21,23 +25,46 @@ module.exports = ({ filename, module_name, version }, { uniqueId }) => {
21
25
  path: appBuild,
22
26
  filename: `${filename}.${version}.js`,
23
27
  library: `${module_name}@${version}`,
24
- libraryTarget: 'amd',
28
+ libraryTarget: "amd",
25
29
  },
26
- externals: ['react', 'react-dom', 'three', 'lodash', 'd3', '@material-ui/styles'],
30
+ externals: [
31
+ "react",
32
+ "react-dom",
33
+ "three",
34
+ "lodash",
35
+ "d3",
36
+ "@material-ui/styles",
37
+ ],
27
38
  devtool: false,
28
39
  plugins: [
29
40
  new webpack.ProvidePlugin({
30
- THREE: 'three',
31
- React: 'react',
32
- ReactDom: 'react-dom',
33
- })
34
- ]
35
- }
41
+ THREE: "three",
42
+ React: "react",
43
+ ReactDom: "react-dom",
44
+ }),
45
+ ],
46
+ };
36
47
 
37
48
  if (webpackConfigExtendFn) {
38
49
  return webpackConfigExtendFn(cf, {
39
- production: true
40
- })
50
+ production: true,
51
+ });
52
+ }
53
+
54
+ if (removeConsole) {
55
+ cf["optimization"] = {
56
+ minimizer: [
57
+ new TerserWebpackPlugin({
58
+ parallel: true,
59
+ terserOptions: {
60
+ compress: {
61
+ drop_console: true,
62
+ },
63
+ },
64
+ }),
65
+ ],
66
+ };
41
67
  }
68
+
42
69
  return cf;
43
70
  };
@@ -1,137 +1,133 @@
1
- const { appSrc, ownLoaders, cliNodeModules } = require('../config/paths');
1
+ const { appSrc, ownLoaders, cliNodeModules } = require("../config/paths");
2
2
 
3
- module.exports = function ({
4
- isProduction,
5
- uniqueId,
6
- entrys
7
- }) {
8
- return {
9
- stats: 'errors-only',
10
- module: {
11
- rules: [
12
- // three有些插件需要读全局变量
13
- {
14
- test: /three\.module/,
15
- loader: 'expose-loader',
16
- options: {
17
- exposes: {
18
- globalName: 'THREE',
19
- override: true
20
- }
21
- },
22
- },
3
+ module.exports = function ({ isProduction, uniqueId, entrys }) {
4
+ return {
5
+ stats: "errors-only",
6
+ module: {
7
+ rules: [
8
+ // three有些插件需要读全局变量
9
+ {
10
+ test: /three\.module/,
11
+ loader: "expose-loader",
12
+ options: {
13
+ exposes: {
14
+ globalName: "THREE",
15
+ override: true,
16
+ },
17
+ },
18
+ },
19
+ {
20
+ test: /\.worker\.(js|ts)$/,
21
+ use: {
22
+ loader: "worker-loader",
23
+ },
24
+ },
23
25
 
26
+ {
27
+ test: /\.(js|mjs|jsx|ts|tsx)$/,
28
+ include: appSrc,
29
+ loader: require.resolve("babel-loader"),
30
+ options: {
31
+ customize: require.resolve(
32
+ "babel-preset-react-app/webpack-overrides"
33
+ ),
34
+ presets: [require.resolve("babel-preset-react-app")],
35
+ plugins: [
36
+ [
37
+ require.resolve("babel-plugin-named-asset-import"),
24
38
  {
25
- test: /\.(js|mjs|jsx|ts|tsx)$/,
26
- include: appSrc,
27
- loader: require.resolve('babel-loader'),
28
- options: {
29
- customize: require.resolve(
30
- 'babel-preset-react-app/webpack-overrides'
31
- ),
32
- presets: [require.resolve('babel-preset-react-app')],
33
- plugins: [
34
- [
35
- require.resolve('babel-plugin-named-asset-import'),
36
- {
37
- loaderMap: {
38
- svg: {
39
- ReactComponent:
40
- '@svgr/webpack?-svgo,+titleProp,+ref![path]',
41
- },
42
- },
43
- },
44
- ],
45
- ],
46
- cacheDirectory: false,
47
- cacheCompression: false,
39
+ loaderMap: {
40
+ svg: {
41
+ ReactComponent:
42
+ "@svgr/webpack?-svgo,+titleProp,+ref![path]",
48
43
  },
44
+ },
49
45
  },
50
- {
51
- // 修改入口文件
52
- test: Object.values(entrys), // 仅匹配所有组件的index文件
53
- loader: 'react-entry-loader',
54
- options: {
55
- isBuild: isProduction,
56
- uniqueId
57
- }
58
- },
46
+ ],
47
+ ],
48
+ cacheDirectory: false,
49
+ cacheCompression: false,
50
+ },
51
+ },
52
+ {
53
+ // 修改入口文件
54
+ test: Object.values(entrys), // 仅匹配所有组件的index文件
55
+ loader: "react-entry-loader",
56
+ options: {
57
+ isBuild: isProduction,
58
+ uniqueId,
59
+ },
60
+ },
59
61
 
60
- {
61
- test: /\.js\.map$/,
62
- use: {
63
- loader: 'file-loader',
64
- },
65
- },
62
+ {
63
+ test: /\.js\.map$/,
64
+ use: {
65
+ loader: "file-loader",
66
+ },
67
+ },
66
68
 
69
+ {
70
+ test: /\.css$/,
71
+ oneOf: [
72
+ {
73
+ test: /\.(M|m)odule\.css$/,
74
+ use: [
67
75
  {
68
- test: /\.css$/,
69
- oneOf: [
70
- {
71
- test: /\.(M|m)odule\.css$/,
72
- use: [
73
- {
74
- loader: 'style-loader',
75
- },
76
- {
77
- loader: 'css-loader',
78
- options: {
79
- modules: {
80
- localIdentName: isProduction ? '[name]_[local]_[hash:base64:5]' : '[path][name]__[local]',
81
- }
82
- },
83
- },
84
- ]
85
- },
86
- {
87
- use: ['style-loader', 'css-loader']
88
- }
89
- ]
90
- },
91
- {
92
- test: /\.less$/,
93
- include: [appSrc],
94
- use: [
95
- {
96
- loader: 'style-loader',
97
- },
98
- {
99
- loader: 'css-loader',
100
- options: {
101
- modules: true,
102
- },
103
- },
104
- {
105
- loader: 'less-loader',
106
- },
107
- ],
76
+ loader: "style-loader",
108
77
  },
109
78
  {
110
- // exclude: /node_modules/,
111
- test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
112
- loader: 'url-loader',
113
- options: {
114
- limit: 20 * 1024 * 1024,
115
- }
79
+ loader: "css-loader",
80
+ options: {
81
+ modules: {
82
+ localIdentName: isProduction
83
+ ? "[name]_[local]_[hash:base64:5]"
84
+ : "[path][name]__[local]",
85
+ },
86
+ },
116
87
  },
117
- ].filter(Boolean),
88
+ ],
89
+ },
90
+ {
91
+ use: ["style-loader", "css-loader"],
92
+ },
93
+ ],
118
94
  },
119
-
120
- resolveLoader: {
121
- modules: [
122
- 'node_modules',
123
- ownLoaders,
124
- cliNodeModules,
125
- ]
95
+ {
96
+ test: /\.less$/,
97
+ include: [appSrc],
98
+ use: [
99
+ {
100
+ loader: "style-loader",
101
+ },
102
+ {
103
+ loader: "css-loader",
104
+ options: {
105
+ modules: true,
106
+ },
107
+ },
108
+ {
109
+ loader: "less-loader",
110
+ },
111
+ ],
126
112
  },
127
-
128
- resolve: {
129
- extensions: ['.js', '.jsx'],
130
- modules: [
131
- 'node_modules',
132
- cliNodeModules
133
- ]
113
+ {
114
+ // exclude: /node_modules/,
115
+ test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
116
+ loader: "url-loader",
117
+ options: {
118
+ limit: 20 * 1024 * 1024,
119
+ },
134
120
  },
121
+ ].filter(Boolean),
122
+ },
123
+
124
+ resolveLoader: {
125
+ modules: ["node_modules", ownLoaders, cliNodeModules],
126
+ },
135
127
 
136
- }
137
- }
128
+ resolve: {
129
+ extensions: [".js", ".jsx", ".ts", ".tsx"],
130
+ modules: ["node_modules", cliNodeModules],
131
+ },
132
+ };
133
+ };
package/launcher/build.js CHANGED
@@ -16,7 +16,7 @@ function canReadAsset(asset) {
16
16
  }
17
17
 
18
18
  module.exports = (name, option = {}) => {
19
- const { unique = true } = option;
19
+ const { unique = true, removeConsole } = option;
20
20
  return new Promise((resolve, reject) => {
21
21
  // 检查组件是否存在
22
22
  // 开始打包
@@ -43,7 +43,9 @@ module.exports = (name, option = {}) => {
43
43
  const { base } = checkComponentFiles(sourcePath);
44
44
  base.filename = `${base.module_name}`;
45
45
  base.module_name = `${base.module_name}${unique ? "." + easyvcid : ""}`;
46
- const compiler = webpack(getWebpackConfig(base, { uniqueId: easyvcid }));
46
+ const compiler = webpack(
47
+ getWebpackConfig(base, { uniqueId: easyvcid, removeConsole })
48
+ );
47
49
 
48
50
  console.log("Creating an optimized production build...");
49
51
 
package/launcher/start.js CHANGED
@@ -148,7 +148,7 @@ function start({ port, modules }) {
148
148
 
149
149
  function getBuildEntrys(modules = []) {
150
150
  // 优先级
151
- const suffix = ["jsx", "js"];
151
+ const suffix = ["jsx", "tsx", "js", "ts"];
152
152
 
153
153
  return new Promise((resolve, reject) => {
154
154
  // 两种获取方式配置方式
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-component-builder",
3
- "version": "0.14.1",
3
+ "version": "0.16.1",
4
4
  "files": [
5
5
  "launcher",
6
6
  "templates",
@@ -48,13 +48,15 @@
48
48
  "url-loader": "2.3.0",
49
49
  "webpack": "4.42.0",
50
50
  "webpack-dev-server": "3.10.3",
51
- "webpack-manifest-plugin": "2.2.0"
51
+ "webpack-manifest-plugin": "2.2.0",
52
+ "worker-loader": "^3.0.8"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@types/lodash": "^4.14.157",
55
56
  "@types/node": "^12.0.0",
56
57
  "@types/react": "^16.9.0",
57
- "@types/react-dom": "^16.9.0"
58
+ "@types/react-dom": "^16.9.0",
59
+ "terser-webpack-plugin": "^4.2.3"
58
60
  },
59
61
  "easyv": {
60
62
  "src": "examples",