@autobest-ui/scripts 3.0.0-alpha.3 → 3.0.0-alpha.5
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/apiConfig/build.js +64 -0
- package/apiConfig/start.js +54 -0
- package/apiConfig/webpack.prod.api.js +38 -0
- package/bin/api.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const webpack = require('webpack');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const appConfig = require('../common/appConfig');
|
|
4
|
+
const { runCallback } = require('../common/build');
|
|
5
|
+
const getEnvironmentInfo = require('../common/extendEnv');
|
|
6
|
+
const extendWebpackConfigFromProject = require('../common/extendWebpackConfigFromProject');
|
|
7
|
+
const apiConfigFactory = require('./webpack.prod.api');
|
|
8
|
+
|
|
9
|
+
process.env.BABEL_ENV = 'production';
|
|
10
|
+
process.env.NODE_ENV = 'production';
|
|
11
|
+
|
|
12
|
+
process.on('unhandledRejection', err => {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
14
|
+
throw err;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const extendEnv = getEnvironmentInfo();
|
|
18
|
+
|
|
19
|
+
function build() {
|
|
20
|
+
const apiConfig = extendWebpackConfigFromProject(apiConfigFactory, appConfig, extendEnv, {
|
|
21
|
+
isServer: true,
|
|
22
|
+
isHotServer: false,
|
|
23
|
+
isProd: true
|
|
24
|
+
});
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log(chalk.green('Creating an optimized production build...'));
|
|
27
|
+
const apiCompiler = webpack(apiConfig);
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
apiCompiler.run(runCallback(resolve, reject));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
build()
|
|
34
|
+
.then(
|
|
35
|
+
buildInfo => {
|
|
36
|
+
if (buildInfo.warnings.length) {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(buildInfo.warnings.join('\n\n'));
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
|
|
45
|
+
} else {
|
|
46
|
+
// eslint-disable-next-line no-console
|
|
47
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
err => {
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log(err);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
.catch(err => {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.log(err);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const nodemon = require('nodemon');
|
|
2
|
+
const open = require('open');
|
|
3
|
+
const getEnvironmentInfo = require('../common/extendEnv');
|
|
4
|
+
const appConfig = require('../common/appConfig');
|
|
5
|
+
const { getProjectPath, parseArgsToJson } = require('../common/utils');
|
|
6
|
+
|
|
7
|
+
const extendEnv = getEnvironmentInfo();
|
|
8
|
+
|
|
9
|
+
const PORT = process.env.PORT || parseArgsToJson.port || appConfig.startDefaultPort;
|
|
10
|
+
const startOpenPath = appConfig.startOpenPath ? appConfig.startOpenPath : '';
|
|
11
|
+
|
|
12
|
+
process.env.BABEL_ENV = 'development';
|
|
13
|
+
process.env.NODE_ENV = 'development';
|
|
14
|
+
|
|
15
|
+
const options = {
|
|
16
|
+
// 配置文件
|
|
17
|
+
script: getProjectPath(appConfig.apiEntry),
|
|
18
|
+
restartable: 're',
|
|
19
|
+
verbose: true,
|
|
20
|
+
delay: 1000,
|
|
21
|
+
watch: appConfig.hotApiWatch,
|
|
22
|
+
env: {
|
|
23
|
+
PORT: PORT,
|
|
24
|
+
BABEL_ENV: 'development',
|
|
25
|
+
NODE_ENV: 'development',
|
|
26
|
+
...extendEnv.raw
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let isOpened = false;
|
|
31
|
+
|
|
32
|
+
nodemon(options)
|
|
33
|
+
.on('start', () => {
|
|
34
|
+
// 启动时的事件
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.log('Server app has started');
|
|
37
|
+
if (!isOpened) {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
open(`http://localhost:${PORT}${startOpenPath}`);
|
|
40
|
+
}, 3000);
|
|
41
|
+
isOpened = true;
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.on('quit', () => {
|
|
45
|
+
// 退出时的事件
|
|
46
|
+
// eslint-disable-next-line no-console
|
|
47
|
+
console.log('Server app has quit');
|
|
48
|
+
process.exit();
|
|
49
|
+
})
|
|
50
|
+
.on('restart', () => {
|
|
51
|
+
// 重启时的事件
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.log('Server app has restarted');
|
|
54
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { merge } = require('webpack-merge');
|
|
2
|
+
const { getProjectPath, deleteFolders } = require('../common/utils');
|
|
3
|
+
const webpackCommon = require('../common/webpack.common');
|
|
4
|
+
|
|
5
|
+
module.exports = function (appConfig, extendEnv, { isServer, isHotServer, isProd }) {
|
|
6
|
+
const result = merge(webpackCommon(appConfig, extendEnv, { isProd, isServer, isHotServer }), {
|
|
7
|
+
target: 'node',
|
|
8
|
+
entry: getProjectPath(appConfig.apiEntry),
|
|
9
|
+
output: {
|
|
10
|
+
path: getProjectPath(appConfig.apiOutputPath),
|
|
11
|
+
publicPath: '/',
|
|
12
|
+
filename: 'index.js',
|
|
13
|
+
libraryTarget: 'commonjs2',
|
|
14
|
+
chunkFilename: '[name].[chunkhash].js'
|
|
15
|
+
},
|
|
16
|
+
module: {
|
|
17
|
+
rules: [
|
|
18
|
+
{
|
|
19
|
+
oneOf: [
|
|
20
|
+
{
|
|
21
|
+
test: /\.(scss|css|sass)$/,
|
|
22
|
+
use: [
|
|
23
|
+
{
|
|
24
|
+
loader: require.resolve('ignore-loader')
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const buildServerOutput = getProjectPath(result.output.path);
|
|
35
|
+
deleteFolders(buildServerOutput);
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
};
|
package/bin/api.js
CHANGED
|
@@ -9,7 +9,7 @@ const spawn = require('cross-spawn');
|
|
|
9
9
|
|
|
10
10
|
const args = process.argv.slice(2);
|
|
11
11
|
|
|
12
|
-
const scriptIndex = args.findIndex(x => x === 'build' || x === 'start'
|
|
12
|
+
const scriptIndex = args.findIndex(x => x === 'build' || x === 'start');
|
|
13
13
|
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
14
14
|
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobest-ui/scripts",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "utils for project tools",
|
|
6
6
|
"bin": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"bin",
|
|
23
23
|
"spaConfig",
|
|
24
24
|
"ssrConfig",
|
|
25
|
+
"apiConfig",
|
|
25
26
|
"common"
|
|
26
27
|
],
|
|
27
28
|
"keywords": [
|