@easyv/react-component-builder 0.17.1 → 0.18.0

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.
package/config/paths.js CHANGED
@@ -1,24 +1,24 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const __cwd = process.cwd();
5
- const __root = path.resolve(__dirname, '..');
6
- const appPackage = require(path.join(__cwd, 'package.json'));
7
- const userHome = require('os').homedir();
8
-
9
- module.exports = {
10
- appPackage,
11
- appBuild: path.resolve(__cwd, 'build'),
12
- appSrc: path.resolve(__cwd, appPackage.easyv.src || 'src'),
13
- appComponents: path.resolve(
14
- __cwd,
15
- (appPackage.easyv || {}).components || 'src/components',
16
- ),
17
- webpackConfigExtend: path.resolve(__cwd, 'webpack.extend.js'),
18
- public: path.resolve(__root, 'public'),
19
- ownLoaders: path.resolve(__root, 'loaders'),
20
- templates: path.resolve(__root, 'templates'),
21
- cliNodeModules: path.join(__root, 'node_modules'),
22
- customTemplatesRoot: path.join(userHome, 'easyv_custom_templates'),
23
- __root,
24
- };
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const __cwd = process.cwd();
5
+ const __root = path.resolve(__dirname, '..');
6
+ const appPackage = require(path.join(__cwd, 'package.json'));
7
+ const userHome = require('os').homedir();
8
+
9
+ module.exports = {
10
+ appPackage,
11
+ appBuild: path.resolve(__cwd, 'build'),
12
+ appSrc: path.resolve(__cwd, appPackage.easyv.src || 'src'),
13
+ appComponents: path.resolve(
14
+ __cwd,
15
+ (appPackage.easyv || {}).components || 'src/components',
16
+ ),
17
+ webpackConfigExtend: path.resolve(__cwd, 'webpack.extend.js'),
18
+ public: path.resolve(__root, 'public'),
19
+ ownLoaders: path.resolve(__root, 'loaders'),
20
+ templates: path.resolve(__root, 'templates'),
21
+ cliNodeModules: path.join(__root, 'node_modules'),
22
+ customTemplatesRoot: path.join(userHome, 'easyv_custom_templates'),
23
+ __root,
24
+ };
@@ -1,70 +1,70 @@
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");
7
-
8
- let webpackConfigExtendFn;
9
- if (fs.existsSync(webpackConfigExtend)) {
10
- webpackConfigExtendFn = require(webpackConfigExtend);
11
- }
12
-
13
- process.env.NODE_ENV = "production";
14
-
15
- module.exports = (
16
- { filename, module_name, version },
17
- { uniqueId, removeConsole }
18
- ) => {
19
- const entry = path.resolve(appComponents, filename, "index");
20
- const cf = {
21
- ...commonConfig({ isProduction: true, uniqueId, entrys: [entry] }),
22
- mode: process.env.NODE_ENV,
23
- entry,
24
- output: {
25
- path: appBuild,
26
- filename: `${filename}.${version}.js`,
27
- library: `${module_name}@${version}`,
28
- libraryTarget: "amd",
29
- },
30
- externals: [
31
- "react",
32
- "react-dom",
33
- "three",
34
- "lodash",
35
- "d3",
36
- "@material-ui/styles",
37
- ],
38
- devtool: false,
39
- plugins: [
40
- new webpack.ProvidePlugin({
41
- THREE: "three",
42
- React: "react",
43
- ReactDom: "react-dom",
44
- }),
45
- ],
46
- };
47
-
48
- if (webpackConfigExtendFn) {
49
- return webpackConfigExtendFn(cf, {
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
- };
67
- }
68
-
69
- return cf;
70
- };
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");
7
+
8
+ let webpackConfigExtendFn;
9
+ if (fs.existsSync(webpackConfigExtend)) {
10
+ webpackConfigExtendFn = require(webpackConfigExtend);
11
+ }
12
+
13
+ process.env.NODE_ENV = "production";
14
+
15
+ module.exports = (
16
+ { filename, module_name, version },
17
+ { uniqueId, removeConsole }
18
+ ) => {
19
+ const entry = path.resolve(appComponents, filename, "index");
20
+ const cf = {
21
+ ...commonConfig({ isProduction: true, uniqueId, entrys: [entry] }),
22
+ mode: process.env.NODE_ENV,
23
+ entry,
24
+ output: {
25
+ path: appBuild,
26
+ filename: `${filename}.${version}.js`,
27
+ library: `${module_name}@${version}`,
28
+ libraryTarget: "amd",
29
+ },
30
+ externals: [
31
+ "react",
32
+ "react-dom",
33
+ "three",
34
+ "lodash",
35
+ "d3",
36
+ "@material-ui/styles",
37
+ ],
38
+ devtool: false,
39
+ plugins: [
40
+ new webpack.ProvidePlugin({
41
+ THREE: "three",
42
+ React: "react",
43
+ ReactDom: "react-dom",
44
+ }),
45
+ ],
46
+ };
47
+
48
+ if (webpackConfigExtendFn) {
49
+ return webpackConfigExtendFn(cf, {
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
+ };
67
+ }
68
+
69
+ return cf;
70
+ };
@@ -1,126 +1,126 @@
1
- const { appSrc, ownLoaders, cliNodeModules } = require("../config/paths");
2
-
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: /\.(js|mjs|jsx|ts|tsx)$/,
21
- include: appSrc,
22
- loader: require.resolve("babel-loader"),
23
- options: {
24
- customize: require.resolve(
25
- "babel-preset-react-app/webpack-overrides"
26
- ),
27
- presets: [require.resolve("babel-preset-react-app")],
28
- plugins: [
29
- [
30
- require.resolve("babel-plugin-named-asset-import"),
31
- {
32
- loaderMap: {
33
- svg: {
34
- ReactComponent:
35
- "@svgr/webpack?-svgo,+titleProp,+ref![path]",
36
- },
37
- },
38
- },
39
- ],
40
- ],
41
- cacheDirectory: false,
42
- cacheCompression: false,
43
- },
44
- },
45
- {
46
- // 修改入口文件
47
- test: Object.values(entrys), // 仅匹配所有组件的index文件
48
- loader: "react-entry-loader",
49
- options: {
50
- isBuild: isProduction,
51
- uniqueId,
52
- },
53
- },
54
-
55
- {
56
- test: /\.js\.map$/,
57
- use: {
58
- loader: "file-loader",
59
- },
60
- },
61
-
62
- {
63
- test: /\.css$/,
64
- oneOf: [
65
- {
66
- 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
- },
80
- },
81
- ],
82
- },
83
- {
84
- use: ["style-loader", "css-loader"],
85
- },
86
- ],
87
- },
88
- {
89
- test: /\.less$/,
90
- include: [appSrc],
91
- use: [
92
- {
93
- loader: "style-loader",
94
- },
95
- {
96
- loader: "css-loader",
97
- options: {
98
- modules: true,
99
- },
100
- },
101
- {
102
- loader: "less-loader",
103
- },
104
- ],
105
- },
106
- {
107
- // exclude: /node_modules/,
108
- test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
109
- loader: "url-loader",
110
- options: {
111
- limit: 20 * 1024 * 1024,
112
- },
113
- },
114
- ].filter(Boolean),
115
- },
116
-
117
- resolveLoader: {
118
- modules: ["node_modules", ownLoaders, cliNodeModules],
119
- },
120
-
121
- resolve: {
122
- extensions: [".js", ".jsx", ".tsx", ".ts"],
123
- modules: ["node_modules", cliNodeModules],
124
- },
125
- };
126
- };
1
+ const { appSrc, ownLoaders, cliNodeModules } = require("../config/paths");
2
+
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: /\.(js|mjs|jsx|ts|tsx)$/,
21
+ include: appSrc,
22
+ loader: require.resolve("babel-loader"),
23
+ options: {
24
+ customize: require.resolve(
25
+ "babel-preset-react-app/webpack-overrides"
26
+ ),
27
+ presets: [require.resolve("babel-preset-react-app")],
28
+ plugins: [
29
+ [
30
+ require.resolve("babel-plugin-named-asset-import"),
31
+ {
32
+ loaderMap: {
33
+ svg: {
34
+ ReactComponent:
35
+ "@svgr/webpack?-svgo,+titleProp,+ref![path]",
36
+ },
37
+ },
38
+ },
39
+ ],
40
+ ],
41
+ cacheDirectory: false,
42
+ cacheCompression: false,
43
+ },
44
+ },
45
+ {
46
+ // 修改入口文件
47
+ test: Object.values(entrys), // 仅匹配所有组件的index文件
48
+ loader: "react-entry-loader",
49
+ options: {
50
+ isBuild: isProduction,
51
+ uniqueId,
52
+ },
53
+ },
54
+
55
+ {
56
+ test: /\.js\.map$/,
57
+ use: {
58
+ loader: "file-loader",
59
+ },
60
+ },
61
+
62
+ {
63
+ test: /\.css$/,
64
+ oneOf: [
65
+ {
66
+ 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
+ },
80
+ },
81
+ ],
82
+ },
83
+ {
84
+ use: ["style-loader", "css-loader"],
85
+ },
86
+ ],
87
+ },
88
+ {
89
+ test: /\.less$/,
90
+ include: [appSrc],
91
+ use: [
92
+ {
93
+ loader: "style-loader",
94
+ },
95
+ {
96
+ loader: "css-loader",
97
+ options: {
98
+ modules: true,
99
+ },
100
+ },
101
+ {
102
+ loader: "less-loader",
103
+ },
104
+ ],
105
+ },
106
+ {
107
+ // exclude: /node_modules/,
108
+ test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
109
+ loader: "url-loader",
110
+ options: {
111
+ limit: 20 * 1024 * 1024,
112
+ },
113
+ },
114
+ ].filter(Boolean),
115
+ },
116
+
117
+ resolveLoader: {
118
+ modules: ["node_modules", ownLoaders, cliNodeModules],
119
+ },
120
+
121
+ resolve: {
122
+ extensions: [".js", ".jsx", ".tsx", ".ts"],
123
+ modules: ["node_modules", cliNodeModules],
124
+ },
125
+ };
126
+ };
@@ -1,116 +1,116 @@
1
- const HtmlPlugin = require('html-webpack-plugin');
2
- const path = require('path');
3
- const fs = require('fs');
4
- const commonConfig = require('./webpack.config.common');
5
- const webpack = require('webpack');
6
- const { appPackage, public, webpackConfigExtend, cliNodeModules } = require('./paths');
7
-
8
- let webpackConfigExtendFn;
9
- if (fs.existsSync(webpackConfigExtend)) {
10
- webpackConfigExtendFn = require(webpackConfigExtend);
11
- }
12
-
13
- process.env.NODE_ENV = 'development';
14
-
15
- module.exports = ({ port, modules }) => {
16
-
17
- const entrys = modules.reduce((acc, item) => {
18
- acc[item.name] = path.resolve(item.path)
19
- return acc
20
- }, {})
21
-
22
- const cf = {
23
- ...commonConfig({
24
- isProduction: false,
25
- entrys
26
- }),
27
-
28
- mode: 'development',
29
- entry: entrys,
30
- output: {
31
- filename: '[name].js',
32
- globalObject: 'this',
33
- libraryTarget: 'var',
34
- library: '__MAIN__' // 暴露到window上的属性名称
35
- },
36
- devtool: 'source-map',
37
- plugins: [
38
- new webpack.ProvidePlugin({
39
- THREE: 'three',
40
- React: 'react',
41
- ReactDom: 'react-dom',
42
- }),
43
- new HtmlPlugin({
44
- filename: 'index.html',
45
- template: path.join(public, 'home.ejs'),
46
- templateParameters: {
47
- 'modules': Object.keys(entrys).toString()
48
- },
49
- chunks: ['']
50
- }),
51
- ...Object.keys(entrys).map(name => {
52
- return new HtmlPlugin({
53
- filename: `${name}.html`,
54
- template: path.join(public, 'component.ejs'),
55
- templateParameters: {
56
- "module_name": name,
57
- "assets": appPackage.easyv.assets,
58
- },
59
- chunks: [name]
60
- })
61
- })
62
- ],
63
- externals: {
64
- 'react': 'react',
65
- 'react-dom': 'ReactDOM'
66
- },
67
-
68
- devServer: {
69
- port,
70
- hot: false,
71
- quiet: true,
72
- before: function (app, server, compiler) {
73
- var multer = require('multer')
74
- var storage = multer.memoryStorage()
75
- var upload = multer({ storage: storage })
76
- const fileCache = new Map();
77
- // 用户资源上传
78
- app.post('/__develop__/assets', upload.single('file'), function (req, res) {
79
- const a = req.file;
80
- fileCache.set(a.originalname, a.buffer)
81
- res.json({ url: `${req.url}/${a.originalname}` });
82
- });
83
- // 用户资源获取
84
- app.get('/__develop__/assets/:name', function (req, res) {
85
- const file = fileCache.get(req.params.name);
86
- if (!file) return res.status(404);
87
- res.send(file)
88
- });
89
- // 静态资源
90
- app.get('/static/*', function (req, res) {
91
- let filepath;
92
- [cliNodeModules].find((root) => {
93
- const p = req.url.replace('/static', root);
94
- if (fs.existsSync(p)) {
95
- filepath = p;
96
- return true;
97
- }
98
- })
99
- if (!filepath) return res.status(404).end();
100
- fs.readFile(filepath, (err, data) => {
101
- if (err) { return res.status(404).end() }
102
- res.send(data)
103
- })
104
- });
105
- }
106
- }
107
- }
108
-
109
- if (webpackConfigExtendFn) {
110
- return webpackConfigExtendFn(cf, {
111
- production: false
112
- })
113
- }
114
-
115
- return cf;
116
- };
1
+ const HtmlPlugin = require('html-webpack-plugin');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const commonConfig = require('./webpack.config.common');
5
+ const webpack = require('webpack');
6
+ const { appPackage, public, webpackConfigExtend, cliNodeModules } = require('./paths');
7
+
8
+ let webpackConfigExtendFn;
9
+ if (fs.existsSync(webpackConfigExtend)) {
10
+ webpackConfigExtendFn = require(webpackConfigExtend);
11
+ }
12
+
13
+ process.env.NODE_ENV = 'development';
14
+
15
+ module.exports = ({ port, modules }) => {
16
+
17
+ const entrys = modules.reduce((acc, item) => {
18
+ acc[item.name] = path.resolve(item.path)
19
+ return acc
20
+ }, {})
21
+
22
+ const cf = {
23
+ ...commonConfig({
24
+ isProduction: false,
25
+ entrys
26
+ }),
27
+
28
+ mode: 'development',
29
+ entry: entrys,
30
+ output: {
31
+ filename: '[name].js',
32
+ globalObject: 'this',
33
+ libraryTarget: 'var',
34
+ library: '__MAIN__' // 暴露到window上的属性名称
35
+ },
36
+ devtool: 'source-map',
37
+ plugins: [
38
+ new webpack.ProvidePlugin({
39
+ THREE: 'three',
40
+ React: 'react',
41
+ ReactDom: 'react-dom',
42
+ }),
43
+ new HtmlPlugin({
44
+ filename: 'index.html',
45
+ template: path.join(public, 'home.ejs'),
46
+ templateParameters: {
47
+ 'modules': Object.keys(entrys).toString()
48
+ },
49
+ chunks: ['']
50
+ }),
51
+ ...Object.keys(entrys).map(name => {
52
+ return new HtmlPlugin({
53
+ filename: `${name}.html`,
54
+ template: path.join(public, 'component.ejs'),
55
+ templateParameters: {
56
+ "module_name": name,
57
+ "assets": appPackage.easyv.assets,
58
+ },
59
+ chunks: [name]
60
+ })
61
+ })
62
+ ],
63
+ externals: {
64
+ 'react': 'react',
65
+ 'react-dom': 'ReactDOM'
66
+ },
67
+
68
+ devServer: {
69
+ port,
70
+ hot: false,
71
+ quiet: true,
72
+ before: function (app, server, compiler) {
73
+ var multer = require('multer')
74
+ var storage = multer.memoryStorage()
75
+ var upload = multer({ storage: storage })
76
+ const fileCache = new Map();
77
+ // 用户资源上传
78
+ app.post('/__develop__/assets', upload.single('file'), function (req, res) {
79
+ const a = req.file;
80
+ fileCache.set(a.originalname, a.buffer)
81
+ res.json({ url: `${req.url}/${a.originalname}` });
82
+ });
83
+ // 用户资源获取
84
+ app.get('/__develop__/assets/:name', function (req, res) {
85
+ const file = fileCache.get(req.params.name);
86
+ if (!file) return res.status(404);
87
+ res.send(file)
88
+ });
89
+ // 静态资源
90
+ app.get('/static/*', function (req, res) {
91
+ let filepath;
92
+ [cliNodeModules].find((root) => {
93
+ const p = req.url.replace('/static', root);
94
+ if (fs.existsSync(p)) {
95
+ filepath = p;
96
+ return true;
97
+ }
98
+ })
99
+ if (!filepath) return res.status(404).end();
100
+ fs.readFile(filepath, (err, data) => {
101
+ if (err) { return res.status(404).end() }
102
+ res.send(data)
103
+ })
104
+ });
105
+ }
106
+ }
107
+ }
108
+
109
+ if (webpackConfigExtendFn) {
110
+ return webpackConfigExtendFn(cf, {
111
+ production: false
112
+ })
113
+ }
114
+
115
+ return cf;
116
+ };