@easyv/react-component-builder 0.18.1 → 0.19.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.
- package/config/webpack.config.build.js +21 -21
- package/config/webpack.config.js +47 -37
- package/launcher/build.js +43 -32
- package/launcher/start.js +50 -41
- package/package.json +9 -3
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const TerserWebpackPlugin = require(
|
|
4
|
-
const commonConfig = require(
|
|
5
|
-
const { appComponents, appBuild, webpackConfigExtend } = require(
|
|
6
|
-
const webpack = require(
|
|
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
7
|
|
|
8
8
|
let webpackConfigExtendFn;
|
|
9
9
|
if (fs.existsSync(webpackConfigExtend)) {
|
|
10
10
|
webpackConfigExtendFn = require(webpackConfigExtend);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
process.env.NODE_ENV =
|
|
13
|
+
process.env.NODE_ENV = 'production';
|
|
14
14
|
|
|
15
15
|
module.exports = (
|
|
16
16
|
{ filename, module_name, version },
|
|
17
|
-
{ uniqueId, removeConsole }
|
|
17
|
+
{ uniqueId, removeConsole },
|
|
18
18
|
) => {
|
|
19
|
-
const entry = path.resolve(appComponents, filename,
|
|
19
|
+
const entry = path.resolve(appComponents, filename, 'index');
|
|
20
20
|
const cf = {
|
|
21
21
|
...commonConfig({ isProduction: true, uniqueId, entrys: [entry] }),
|
|
22
22
|
mode: process.env.NODE_ENV,
|
|
23
23
|
entry,
|
|
24
24
|
output: {
|
|
25
25
|
path: appBuild,
|
|
26
|
-
filename: `${
|
|
26
|
+
filename: `${module_name}.${version}.js`,
|
|
27
27
|
library: `${module_name}@${version}`,
|
|
28
|
-
libraryTarget:
|
|
28
|
+
libraryTarget: 'amd',
|
|
29
29
|
},
|
|
30
30
|
externals: [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
'react',
|
|
32
|
+
'react-dom',
|
|
33
|
+
'three',
|
|
34
|
+
'lodash',
|
|
35
|
+
'd3',
|
|
36
|
+
'@material-ui/styles',
|
|
37
37
|
],
|
|
38
38
|
devtool: false,
|
|
39
39
|
plugins: [
|
|
40
40
|
new webpack.ProvidePlugin({
|
|
41
|
-
THREE:
|
|
42
|
-
React:
|
|
43
|
-
ReactDom:
|
|
41
|
+
THREE: 'three',
|
|
42
|
+
React: 'react',
|
|
43
|
+
ReactDom: 'react-dom',
|
|
44
44
|
}),
|
|
45
45
|
],
|
|
46
46
|
};
|
|
@@ -52,7 +52,7 @@ module.exports = (
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (removeConsole) {
|
|
55
|
-
cf[
|
|
55
|
+
cf['optimization'] = {
|
|
56
56
|
minimizer: [
|
|
57
57
|
new TerserWebpackPlugin({
|
|
58
58
|
parallel: true,
|
package/config/webpack.config.js
CHANGED
|
@@ -3,7 +3,12 @@ const path = require('path');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const commonConfig = require('./webpack.config.common');
|
|
5
5
|
const webpack = require('webpack');
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
appPackage,
|
|
8
|
+
public: publicPath,
|
|
9
|
+
webpackConfigExtend,
|
|
10
|
+
cliNodeModules,
|
|
11
|
+
} = require('./paths');
|
|
7
12
|
|
|
8
13
|
let webpackConfigExtendFn;
|
|
9
14
|
if (fs.existsSync(webpackConfigExtend)) {
|
|
@@ -13,16 +18,15 @@ if (fs.existsSync(webpackConfigExtend)) {
|
|
|
13
18
|
process.env.NODE_ENV = 'development';
|
|
14
19
|
|
|
15
20
|
module.exports = ({ port, modules }) => {
|
|
16
|
-
|
|
17
21
|
const entrys = modules.reduce((acc, item) => {
|
|
18
|
-
acc[item.name] = path.resolve(item.path)
|
|
19
|
-
return acc
|
|
20
|
-
}, {})
|
|
22
|
+
acc[item.name] = path.resolve(item.path);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
21
25
|
|
|
22
26
|
const cf = {
|
|
23
27
|
...commonConfig({
|
|
24
28
|
isProduction: false,
|
|
25
|
-
entrys
|
|
29
|
+
entrys,
|
|
26
30
|
}),
|
|
27
31
|
|
|
28
32
|
mode: 'development',
|
|
@@ -31,7 +35,7 @@ module.exports = ({ port, modules }) => {
|
|
|
31
35
|
filename: '[name].js',
|
|
32
36
|
globalObject: 'this',
|
|
33
37
|
libraryTarget: 'var',
|
|
34
|
-
library: '__MAIN__' // 暴露到window上的属性名称
|
|
38
|
+
library: '__MAIN__', // 暴露到window上的属性名称
|
|
35
39
|
},
|
|
36
40
|
devtool: 'source-map',
|
|
37
41
|
plugins: [
|
|
@@ -42,27 +46,27 @@ module.exports = ({ port, modules }) => {
|
|
|
42
46
|
}),
|
|
43
47
|
new HtmlPlugin({
|
|
44
48
|
filename: 'index.html',
|
|
45
|
-
template: path.join(
|
|
49
|
+
template: path.join(publicPath, 'home.ejs'),
|
|
46
50
|
templateParameters: {
|
|
47
|
-
|
|
51
|
+
modules: Object.keys(entrys).toString(),
|
|
48
52
|
},
|
|
49
|
-
chunks: ['']
|
|
53
|
+
chunks: [''],
|
|
50
54
|
}),
|
|
51
|
-
...Object.keys(entrys).map(name => {
|
|
55
|
+
...Object.keys(entrys).map((name) => {
|
|
52
56
|
return new HtmlPlugin({
|
|
53
57
|
filename: `${name}.html`,
|
|
54
|
-
template: path.join(
|
|
58
|
+
template: path.join(publicPath, 'component.ejs'),
|
|
55
59
|
templateParameters: {
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
module_name: name,
|
|
61
|
+
assets: appPackage.easyv.assets,
|
|
58
62
|
},
|
|
59
|
-
chunks: [name]
|
|
60
|
-
})
|
|
61
|
-
})
|
|
63
|
+
chunks: [name],
|
|
64
|
+
});
|
|
65
|
+
}),
|
|
62
66
|
],
|
|
63
67
|
externals: {
|
|
64
|
-
|
|
65
|
-
'react-dom': 'ReactDOM'
|
|
68
|
+
react: 'react',
|
|
69
|
+
'react-dom': 'ReactDOM',
|
|
66
70
|
},
|
|
67
71
|
|
|
68
72
|
devServer: {
|
|
@@ -70,21 +74,25 @@ module.exports = ({ port, modules }) => {
|
|
|
70
74
|
hot: false,
|
|
71
75
|
quiet: true,
|
|
72
76
|
before: function (app, server, compiler) {
|
|
73
|
-
var multer = require('multer')
|
|
74
|
-
var storage = multer.memoryStorage()
|
|
75
|
-
var upload = multer({ storage: storage })
|
|
77
|
+
var multer = require('multer');
|
|
78
|
+
var storage = multer.memoryStorage();
|
|
79
|
+
var upload = multer({ storage: storage });
|
|
76
80
|
const fileCache = new Map();
|
|
77
81
|
// 用户资源上传
|
|
78
|
-
app.post(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
app.post(
|
|
83
|
+
'/__develop__/assets',
|
|
84
|
+
upload.single('file'),
|
|
85
|
+
function (req, res) {
|
|
86
|
+
const a = req.file;
|
|
87
|
+
fileCache.set(a.originalname, a.buffer);
|
|
88
|
+
res.json({ url: `${req.url}/${a.originalname}` });
|
|
89
|
+
},
|
|
90
|
+
);
|
|
83
91
|
// 用户资源获取
|
|
84
92
|
app.get('/__develop__/assets/:name', function (req, res) {
|
|
85
93
|
const file = fileCache.get(req.params.name);
|
|
86
94
|
if (!file) return res.status(404);
|
|
87
|
-
res.send(file)
|
|
95
|
+
res.send(file);
|
|
88
96
|
});
|
|
89
97
|
// 静态资源
|
|
90
98
|
app.get('/static/*', function (req, res) {
|
|
@@ -95,21 +103,23 @@ module.exports = ({ port, modules }) => {
|
|
|
95
103
|
filepath = p;
|
|
96
104
|
return true;
|
|
97
105
|
}
|
|
98
|
-
})
|
|
106
|
+
});
|
|
99
107
|
if (!filepath) return res.status(404).end();
|
|
100
108
|
fs.readFile(filepath, (err, data) => {
|
|
101
|
-
if (err) {
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
if (err) {
|
|
110
|
+
return res.status(404).end();
|
|
111
|
+
}
|
|
112
|
+
res.send(data);
|
|
113
|
+
});
|
|
104
114
|
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
108
118
|
|
|
109
119
|
if (webpackConfigExtendFn) {
|
|
110
120
|
return webpackConfigExtendFn(cf, {
|
|
111
|
-
production: false
|
|
112
|
-
})
|
|
121
|
+
production: false,
|
|
122
|
+
});
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
return cf;
|
package/launcher/build.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const chalk = require(
|
|
4
|
-
const webpack = require(
|
|
5
|
-
const filesize = require(
|
|
6
|
-
const { appComponents, appBuild } = require(
|
|
7
|
-
const { checkComponentFiles } = require(
|
|
8
|
-
const getWebpackConfig = require(
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const webpack = require('webpack');
|
|
5
|
+
const filesize = require('filesize');
|
|
6
|
+
const { appComponents, appBuild } = require('../config/paths');
|
|
7
|
+
const { checkComponentFiles } = require('../utils');
|
|
8
|
+
const getWebpackConfig = require('../config/webpack.config.build');
|
|
9
|
+
const { getBuildEntrys } = require('./start');
|
|
9
10
|
|
|
10
11
|
function canReadAsset(asset) {
|
|
11
12
|
return (
|
|
@@ -17,68 +18,78 @@ function canReadAsset(asset) {
|
|
|
17
18
|
|
|
18
19
|
module.exports = (name, option = {}) => {
|
|
19
20
|
const { unique = true, removeConsole } = option;
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
21
22
|
// 检查组件是否存在
|
|
22
23
|
// 开始打包
|
|
23
24
|
// 打包成功 返回bundle路径
|
|
24
|
-
|
|
25
|
-
const
|
|
25
|
+
const result = await getBuildEntrys();
|
|
26
|
+
const componentInfo = result.find((d) => d.name === name);
|
|
27
|
+
const { base } = componentInfo;
|
|
28
|
+
const sourcePath = componentInfo.path.slice(
|
|
29
|
+
0,
|
|
30
|
+
componentInfo.path.lastIndexOf('/'),
|
|
31
|
+
);
|
|
32
|
+
// const sourcePath = path.join(appComponents, name);
|
|
26
33
|
|
|
27
34
|
let easyvcid;
|
|
28
35
|
if (unique) {
|
|
29
36
|
// 生成组件唯一标识
|
|
30
|
-
const easyvc = path.join(sourcePath,
|
|
37
|
+
const easyvc = path.join(sourcePath, '.easyvc');
|
|
31
38
|
if (fs.existsSync(easyvc)) {
|
|
32
|
-
easyvcid = fs.readFileSync(easyvc, { encoding:
|
|
39
|
+
easyvcid = fs.readFileSync(easyvc, { encoding: 'utf8' });
|
|
33
40
|
}
|
|
34
41
|
if (!easyvcid) {
|
|
35
42
|
easyvcid = Array.from({ length: 6 })
|
|
36
43
|
.map(() => Math.random().toString(32).slice(2, 3))
|
|
37
|
-
.join(
|
|
38
|
-
fs.writeFileSync(easyvc, easyvcid, { encoding:
|
|
44
|
+
.join('');
|
|
45
|
+
fs.writeFileSync(easyvc, easyvcid, { encoding: 'utf8' });
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
// 重写base的modulename
|
|
43
|
-
const { base } = checkComponentFiles(sourcePath);
|
|
44
|
-
base.filename = `${
|
|
45
|
-
base.module_name = `${base.module_name}${unique ?
|
|
50
|
+
// const { base } = checkComponentFiles(sourcePath);
|
|
51
|
+
base.filename = `${componentInfo.dirname}`;
|
|
52
|
+
base.module_name = `${base.module_name}${unique ? '.' + easyvcid : ''}`;
|
|
46
53
|
const compiler = webpack(
|
|
47
|
-
getWebpackConfig(base, { uniqueId: easyvcid, removeConsole })
|
|
54
|
+
getWebpackConfig(base, { uniqueId: easyvcid, removeConsole }),
|
|
48
55
|
);
|
|
49
56
|
|
|
50
|
-
console.log(
|
|
57
|
+
console.log('Creating an optimized production build...');
|
|
51
58
|
|
|
52
59
|
compiler.run((err, stats) => {
|
|
53
|
-
const message = stats.toJson({
|
|
60
|
+
const message = stats.toJson({
|
|
61
|
+
all: true,
|
|
62
|
+
warnings: true,
|
|
63
|
+
errors: true,
|
|
64
|
+
});
|
|
54
65
|
|
|
55
66
|
const errors = err || message.errors;
|
|
56
67
|
if (errors.length) {
|
|
57
|
-
console.log(chalk.red(
|
|
58
|
-
console.log(chalk.red(errors +
|
|
68
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
69
|
+
console.log(chalk.red(errors + '\n'));
|
|
59
70
|
process.exit(1);
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
if (message.warnings.length) {
|
|
63
|
-
console.log(chalk.yellow(
|
|
64
|
-
console.log(message.warnings.join(
|
|
74
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
75
|
+
console.log(message.warnings.join('\n\n'));
|
|
65
76
|
} else {
|
|
66
77
|
// successful
|
|
67
|
-
console.log(chalk.green(
|
|
78
|
+
console.log(chalk.green('Compiled successfully.'));
|
|
68
79
|
console.log(`Time: ${message.time / 1000}s`);
|
|
69
80
|
console.log(`Built at: ${new Date(message.builtAt)}\n`);
|
|
70
|
-
console.log(
|
|
81
|
+
console.log('File sizes:\n');
|
|
71
82
|
|
|
72
83
|
message.assets
|
|
73
84
|
.filter((asset) => canReadAsset(asset.name))
|
|
74
85
|
.map((asset) => {
|
|
75
86
|
var fileContents = fs.readFileSync(
|
|
76
|
-
path.resolve(appBuild, asset.name)
|
|
87
|
+
path.resolve(appBuild, asset.name),
|
|
77
88
|
);
|
|
78
89
|
return {
|
|
79
90
|
folder: path.join(
|
|
80
91
|
path.basename(appBuild),
|
|
81
|
-
path.dirname(asset.name)
|
|
92
|
+
path.dirname(asset.name),
|
|
82
93
|
),
|
|
83
94
|
name: path.basename(asset.name),
|
|
84
95
|
size: filesize(fileContents.length),
|
|
@@ -87,11 +98,11 @@ module.exports = (name, option = {}) => {
|
|
|
87
98
|
.sort((a, b) => b.size - a.size)
|
|
88
99
|
.map((asset) => {
|
|
89
100
|
console.log(
|
|
90
|
-
|
|
101
|
+
' ' +
|
|
91
102
|
asset.size +
|
|
92
|
-
|
|
103
|
+
' ' +
|
|
93
104
|
chalk.dim(asset.folder + path.sep) +
|
|
94
|
-
chalk.cyan(asset.name)
|
|
105
|
+
chalk.cyan(asset.name),
|
|
95
106
|
);
|
|
96
107
|
});
|
|
97
108
|
|
package/launcher/start.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const webpack = require(
|
|
2
|
-
const WebpackDevServer = require(
|
|
3
|
-
const getWebpackConfig = require(
|
|
4
|
-
const chalk = require(
|
|
5
|
-
const glob = require(
|
|
6
|
-
const { appComponents, appPackage } = require(
|
|
7
|
-
const { checkComponentFiles } = require(
|
|
8
|
-
const autoAssignPort = require(
|
|
9
|
-
const path = require(
|
|
10
|
-
const openBrowser = require(
|
|
1
|
+
const webpack = require('webpack');
|
|
2
|
+
const WebpackDevServer = require('webpack-dev-server');
|
|
3
|
+
const getWebpackConfig = require('../config/webpack.config');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const glob = require('glob');
|
|
6
|
+
const { appComponents, appPackage } = require('../config/paths');
|
|
7
|
+
const { checkComponentFiles } = require('../utils');
|
|
8
|
+
const autoAssignPort = require('../utils/auto-assign-port');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const openBrowser = require('../utils/openBrowser');
|
|
11
11
|
|
|
12
12
|
const isInteractive = process.stdout.isTTY;
|
|
13
13
|
const DEFAULT_PORT = 3005;
|
|
14
|
-
const HOST = process.env.HOST ||
|
|
14
|
+
const HOST = process.env.HOST || '0.0.0.0';
|
|
15
15
|
let isFirstCompile = true;
|
|
16
16
|
|
|
17
17
|
function clearConsole() {
|
|
18
18
|
process.stdout.write(
|
|
19
|
-
process.platform ===
|
|
19
|
+
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ function printInstructions(appName, urls) {
|
|
|
27
27
|
|
|
28
28
|
if (urls.lanUrlForTerminal) {
|
|
29
29
|
console.log(
|
|
30
|
-
` ${chalk.bold(
|
|
30
|
+
` ${chalk.bold('Local:')} ${urls.localUrlForTerminal}`,
|
|
31
31
|
);
|
|
32
32
|
// console.log(
|
|
33
33
|
// ` ${chalk.bold('On Your Network:')} ${urls.lanUrlForTerminal}`
|
|
@@ -42,7 +42,7 @@ function createCompiler({ appName, config, urls }) {
|
|
|
42
42
|
try {
|
|
43
43
|
compiler = webpack(config);
|
|
44
44
|
} catch (err) {
|
|
45
|
-
console.log(chalk.red(
|
|
45
|
+
console.log(chalk.red('Failed to compile.'));
|
|
46
46
|
console.log();
|
|
47
47
|
console.log(err.message || err);
|
|
48
48
|
console.log();
|
|
@@ -53,16 +53,16 @@ function createCompiler({ appName, config, urls }) {
|
|
|
53
53
|
// recompiling a bundle. WebpackDevServer takes care to pause serving the
|
|
54
54
|
// bundle, so if you refresh, it'll wait instead of serving the old one.
|
|
55
55
|
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
|
|
56
|
-
compiler.hooks.invalid.tap(
|
|
56
|
+
compiler.hooks.invalid.tap('invalid', () => {
|
|
57
57
|
if (isInteractive) {
|
|
58
58
|
clearConsole();
|
|
59
59
|
}
|
|
60
|
-
console.log(
|
|
60
|
+
console.log('Compiling...');
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
// "done" event fires when webpack has finished recompiling the bundle.
|
|
64
64
|
// Whether or not you have warnings or errors, you will get this event.
|
|
65
|
-
compiler.hooks.done.tap(
|
|
65
|
+
compiler.hooks.done.tap('done', async (stats) => {
|
|
66
66
|
if (isInteractive) {
|
|
67
67
|
clearConsole();
|
|
68
68
|
}
|
|
@@ -76,7 +76,7 @@ function createCompiler({ appName, config, urls }) {
|
|
|
76
76
|
const messages = statsData;
|
|
77
77
|
const isSuccessful = !messages.errors.length && !messages.warnings.length;
|
|
78
78
|
if (isSuccessful) {
|
|
79
|
-
console.log(chalk.green(
|
|
79
|
+
console.log(chalk.green('Compiled successfully!'));
|
|
80
80
|
}
|
|
81
81
|
if (isSuccessful && (isInteractive || isFirstCompile)) {
|
|
82
82
|
printInstructions(appName, urls);
|
|
@@ -87,24 +87,24 @@ function createCompiler({ appName, config, urls }) {
|
|
|
87
87
|
if (messages.errors.length > 1) {
|
|
88
88
|
messages.errors.length = 1;
|
|
89
89
|
}
|
|
90
|
-
console.log(chalk.red(
|
|
91
|
-
console.log(messages.errors.join(
|
|
90
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
91
|
+
console.log(messages.errors.join('\n\n'));
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (messages.warnings.length) {
|
|
96
|
-
console.log(chalk.yellow(
|
|
97
|
-
console.log(messages.warnings.join(
|
|
96
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
97
|
+
console.log(messages.warnings.join('\n\n'));
|
|
98
98
|
|
|
99
99
|
console.log(
|
|
100
|
-
|
|
101
|
-
chalk.underline(chalk.yellow(
|
|
102
|
-
|
|
100
|
+
'\nSearch for the ' +
|
|
101
|
+
chalk.underline(chalk.yellow('keywords')) +
|
|
102
|
+
' to learn more about each warning.',
|
|
103
103
|
);
|
|
104
104
|
console.log(
|
|
105
|
-
|
|
106
|
-
chalk.cyan(
|
|
107
|
-
|
|
105
|
+
'To ignore, add ' +
|
|
106
|
+
chalk.cyan('// eslint-disable-next-line') +
|
|
107
|
+
' to the line before.\n',
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
});
|
|
@@ -134,11 +134,11 @@ function start({ port, modules }) {
|
|
|
134
134
|
clearConsole();
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
console.log(chalk.cyan(
|
|
137
|
+
console.log(chalk.cyan('Starting the development server...\n'));
|
|
138
138
|
openBrowser(url);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
[
|
|
141
|
+
['SIGINT', 'SIGTERM'].forEach(function (sig) {
|
|
142
142
|
process.on(sig, function () {
|
|
143
143
|
server.close();
|
|
144
144
|
process.exit();
|
|
@@ -148,15 +148,15 @@ function start({ port, modules }) {
|
|
|
148
148
|
|
|
149
149
|
function getBuildEntrys(modules = []) {
|
|
150
150
|
// 优先级
|
|
151
|
-
const suffix = [
|
|
151
|
+
const suffix = ['jsx', 'tsx', 'js', 'ts'];
|
|
152
152
|
|
|
153
|
-
return new Promise((resolve
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
154
|
// 两种获取方式配置方式
|
|
155
|
-
// new configs: ['config/main.json', 'config/main.data.json']
|
|
155
|
+
// new configs: ['config/main.(json|js)', 'config/main.data.(json|js)']
|
|
156
156
|
// old configs: ['config/base.js', 'config/config.js', 'mock/data.js']
|
|
157
157
|
|
|
158
158
|
glob(
|
|
159
|
-
`*/index.+(${suffix.join(
|
|
159
|
+
`*/index.+(${suffix.join('|')})`,
|
|
160
160
|
{
|
|
161
161
|
cwd: appComponents,
|
|
162
162
|
},
|
|
@@ -169,10 +169,17 @@ function getBuildEntrys(modules = []) {
|
|
|
169
169
|
if (!matches.length) process.exit();
|
|
170
170
|
|
|
171
171
|
const dir = matches.reduce((acc, path) => {
|
|
172
|
-
const name = path.slice(0, path.indexOf(
|
|
173
|
-
if (modules.length &&
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
const name = path.slice(0, path.indexOf('/'));
|
|
173
|
+
if (modules.length && modules.indexOf(name) === -1) {
|
|
174
|
+
// 排除不打包的 如果目录是空的则忽略
|
|
175
|
+
return acc;
|
|
176
|
+
}
|
|
177
|
+
if (!acc[name]) {
|
|
178
|
+
acc[name] = [path];
|
|
179
|
+
} else {
|
|
180
|
+
acc[name].push(path);
|
|
181
|
+
}
|
|
182
|
+
|
|
176
183
|
return acc;
|
|
177
184
|
}, {});
|
|
178
185
|
|
|
@@ -183,7 +190,7 @@ function getBuildEntrys(modules = []) {
|
|
|
183
190
|
let indexPath;
|
|
184
191
|
suffix.every((ext) => {
|
|
185
192
|
const i = dir[dirname].findIndex((path) =>
|
|
186
|
-
path.endsWith(
|
|
193
|
+
path.endsWith('.' + ext),
|
|
187
194
|
);
|
|
188
195
|
return i > -1
|
|
189
196
|
? ((indexPath = path.join(appComponents, dir[dirname][i])), false)
|
|
@@ -191,7 +198,7 @@ function getBuildEntrys(modules = []) {
|
|
|
191
198
|
});
|
|
192
199
|
|
|
193
200
|
const { base } = checkComponentFiles(
|
|
194
|
-
path.join(appComponents, dirname)
|
|
201
|
+
path.join(appComponents, dirname),
|
|
195
202
|
);
|
|
196
203
|
|
|
197
204
|
// 组件名称重复检查
|
|
@@ -215,7 +222,7 @@ function getBuildEntrys(modules = []) {
|
|
|
215
222
|
} else {
|
|
216
223
|
process.exit();
|
|
217
224
|
}
|
|
218
|
-
}
|
|
225
|
+
},
|
|
219
226
|
);
|
|
220
227
|
});
|
|
221
228
|
}
|
|
@@ -227,3 +234,5 @@ module.exports = (modules) => {
|
|
|
227
234
|
});
|
|
228
235
|
});
|
|
229
236
|
};
|
|
237
|
+
|
|
238
|
+
module.exports.getBuildEntrys = getBuildEntrys;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyv/react-component-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"launcher",
|
|
6
6
|
"templates",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "node scripts/start.js",
|
|
14
14
|
"build": "node scripts/build.js",
|
|
15
|
-
"generate": "node scripts/generate.js"
|
|
15
|
+
"generate": "node scripts/generate.js",
|
|
16
|
+
"push": "npm publish",
|
|
17
|
+
"postpublish": "sync-to-mirror"
|
|
16
18
|
},
|
|
17
19
|
"dependencies": {
|
|
18
20
|
"@babel/core": "7.9.0",
|
|
@@ -51,6 +53,7 @@
|
|
|
51
53
|
"webpack-manifest-plugin": "2.2.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
56
|
+
"@easyv/sync-to-mirror": "^0.0.2",
|
|
54
57
|
"@types/lodash": "^4.14.157",
|
|
55
58
|
"@types/node": "^12.0.0",
|
|
56
59
|
"@types/react": "^16.9.0",
|
|
@@ -66,5 +69,8 @@
|
|
|
66
69
|
"test": "http://172.16.10.70:1337"
|
|
67
70
|
},
|
|
68
71
|
"assets": "https://easyv-develop.oss-cn-hangzhou.aliyuncs.com/"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
75
|
}
|
|
70
|
-
}
|
|
76
|
+
}
|