@autobest-ui/scripts 0.0.6 → 0.1.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/README.md +120 -91
- package/bin/spa.js +44 -44
- package/bin/ssr.js +44 -44
- package/common/appConfig.js +11 -11
- package/common/build.js +40 -40
- package/common/extendEnv.js +49 -49
- package/common/formatWebpackMessages.js +97 -97
- package/common/getCSSModuleLocalIdent.js +14 -14
- package/common/start.js +71 -71
- package/common/utils.js +64 -59
- package/common/version.js +23 -23
- package/common/webpack.common.js +218 -193
- package/package.json +2 -3
- package/spaConfig/build.js +65 -65
- package/spaConfig/start.js +4 -4
- package/spaConfig/webpack.base.js +28 -28
- package/spaConfig/webpack.dev.js +45 -45
- package/spaConfig/webpack.prod.js +78 -78
- package/ssrConfig/build.js +82 -82
- package/ssrConfig/server.js +144 -144
- package/ssrConfig/start.js +4 -4
- package/ssrConfig/webpack.base.js +46 -60
- package/ssrConfig/webpack.dev.client.js +31 -31
- package/ssrConfig/webpack.dev.js +58 -58
- package/ssrConfig/webpack.dev.server.js +58 -58
- package/ssrConfig/webpack.prod.client.js +92 -92
- package/ssrConfig/webpack.prod.server.js +50 -50
package/spaConfig/webpack.dev.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
const merge = require('webpack-merge');
|
|
2
|
-
const ip = require('ip');
|
|
3
|
-
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
4
|
-
const baseConfig = require('./webpack.base');
|
|
5
|
-
const { getProjectPath } = require('../common/utils');
|
|
6
|
-
|
|
7
|
-
const HOST = process.env.HOST || ip.address() || 'localhost';
|
|
8
|
-
|
|
9
|
-
module.exports = function(appConfig, extendEnv) {
|
|
10
|
-
return merge(baseConfig(false, appConfig, extendEnv), {
|
|
11
|
-
entry: getProjectPath(appConfig.startEntry),
|
|
12
|
-
output: {
|
|
13
|
-
publicPath: appConfig.startOutput.publicPath || '/',
|
|
14
|
-
path: appConfig.startOutput.path,
|
|
15
|
-
pathinfo: true,
|
|
16
|
-
futureEmitAssets: true,
|
|
17
|
-
filename: 'bundle.js',
|
|
18
|
-
chunkFilename: '[name].chunk.js'
|
|
19
|
-
},
|
|
20
|
-
node: {
|
|
21
|
-
fs: 'empty'
|
|
22
|
-
},
|
|
23
|
-
plugins: [
|
|
24
|
-
// 相关配置文档:https://github.com/geowarin/friendly-errors-webpack-plugin
|
|
25
|
-
new FriendlyErrorsPlugin({
|
|
26
|
-
compilationSuccessInfo: {
|
|
27
|
-
messages: [
|
|
28
|
-
`localhost运行链接: http://localhost:${appConfig.port}${appConfig.startOpenPath}\n`,
|
|
29
|
-
`ip运行链接: http://${HOST}:${appConfig.port}${appConfig.startOpenPath}\n`
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
onErrors: null,
|
|
33
|
-
clearConsole: true
|
|
34
|
-
})
|
|
35
|
-
],
|
|
36
|
-
optimization: {
|
|
37
|
-
minimize: false,
|
|
38
|
-
splitChunks: {
|
|
39
|
-
chunks: 'all',
|
|
40
|
-
name: false
|
|
41
|
-
},
|
|
42
|
-
runtimeChunk: true
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
1
|
+
const merge = require('webpack-merge');
|
|
2
|
+
const ip = require('ip');
|
|
3
|
+
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
4
|
+
const baseConfig = require('./webpack.base');
|
|
5
|
+
const { getProjectPath } = require('../common/utils');
|
|
6
|
+
|
|
7
|
+
const HOST = process.env.HOST || ip.address() || 'localhost';
|
|
8
|
+
|
|
9
|
+
module.exports = function(appConfig, extendEnv) {
|
|
10
|
+
return merge(baseConfig(false, appConfig, extendEnv), {
|
|
11
|
+
entry: getProjectPath(appConfig.startEntry),
|
|
12
|
+
output: {
|
|
13
|
+
publicPath: appConfig.startOutput.publicPath || '/',
|
|
14
|
+
path: appConfig.startOutput.path,
|
|
15
|
+
pathinfo: true,
|
|
16
|
+
futureEmitAssets: true,
|
|
17
|
+
filename: 'bundle.js',
|
|
18
|
+
chunkFilename: '[name].chunk.js'
|
|
19
|
+
},
|
|
20
|
+
node: {
|
|
21
|
+
fs: 'empty'
|
|
22
|
+
},
|
|
23
|
+
plugins: [
|
|
24
|
+
// 相关配置文档:https://github.com/geowarin/friendly-errors-webpack-plugin
|
|
25
|
+
new FriendlyErrorsPlugin({
|
|
26
|
+
compilationSuccessInfo: {
|
|
27
|
+
messages: [
|
|
28
|
+
`localhost运行链接: http://localhost:${appConfig.port}${appConfig.startOpenPath}\n`,
|
|
29
|
+
`ip运行链接: http://${HOST}:${appConfig.port}${appConfig.startOpenPath}\n`
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
onErrors: null,
|
|
33
|
+
clearConsole: true
|
|
34
|
+
})
|
|
35
|
+
],
|
|
36
|
+
optimization: {
|
|
37
|
+
minimize: false,
|
|
38
|
+
splitChunks: {
|
|
39
|
+
chunks: 'all',
|
|
40
|
+
name: false
|
|
41
|
+
},
|
|
42
|
+
runtimeChunk: true
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
const merge = require('webpack-merge');
|
|
2
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
3
|
-
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
|
|
4
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
|
-
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
6
|
-
const safePostCssParser = require('postcss-safe-parser');
|
|
7
|
-
const baseConfig = require('./webpack.base');
|
|
8
|
-
const { getProjectPath, deleteFolders } = require('../common/utils');
|
|
9
|
-
|
|
10
|
-
module.exports = function(appConfig, extendEnv) {
|
|
11
|
-
const outputPath = getProjectPath(appConfig.buildOutput.path);
|
|
12
|
-
deleteFolders(outputPath);
|
|
13
|
-
|
|
14
|
-
return merge(baseConfig(true, appConfig, extendEnv), {
|
|
15
|
-
// 打包的入口文件
|
|
16
|
-
entry: getProjectPath(appConfig.buildEntry),
|
|
17
|
-
// 打包的出口
|
|
18
|
-
output: {
|
|
19
|
-
publicPath: appConfig.buildOutput.publicPath || '/',
|
|
20
|
-
path: outputPath,
|
|
21
|
-
// 入口文件生产的js
|
|
22
|
-
filename: `js/[name].chunk.js?v=${extendEnv.version}`,
|
|
23
|
-
// 非入口文件生产的js
|
|
24
|
-
chunkFilename: `js/[name].chunk.js?v=${extendEnv.version}`
|
|
25
|
-
},
|
|
26
|
-
node: {
|
|
27
|
-
fs: 'empty'
|
|
28
|
-
},
|
|
29
|
-
plugins: [
|
|
30
|
-
new ScriptExtHtmlWebpackPlugin({
|
|
31
|
-
defaultAttribute: 'async',
|
|
32
|
-
preload: /\.js\?v=/
|
|
33
|
-
})
|
|
34
|
-
],
|
|
35
|
-
optimization: {
|
|
36
|
-
concatenateModules: true,
|
|
37
|
-
minimizer: [
|
|
38
|
-
// 压缩js
|
|
39
|
-
new TerserPlugin({
|
|
40
|
-
cache: true,
|
|
41
|
-
parallel: true,
|
|
42
|
-
sourceMap: true
|
|
43
|
-
}),
|
|
44
|
-
|
|
45
|
-
// 压缩css
|
|
46
|
-
new OptimizeCSSAssetsPlugin({
|
|
47
|
-
cssProcessorOptions: {
|
|
48
|
-
parser: safePostCssParser,
|
|
49
|
-
map: {
|
|
50
|
-
inline: false,
|
|
51
|
-
annotation: false
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
],
|
|
56
|
-
splitChunks: {
|
|
57
|
-
chunks: 'initial',
|
|
58
|
-
minSize: 0,
|
|
59
|
-
maxAsyncRequests: 5,
|
|
60
|
-
maxInitialRequests: 3,
|
|
61
|
-
automaticNameDelimiter: '~',
|
|
62
|
-
name: true,
|
|
63
|
-
cacheGroups: {
|
|
64
|
-
vendor: {
|
|
65
|
-
test: /[\\/]node_modules[\\/]/,
|
|
66
|
-
chunks: 'initial',
|
|
67
|
-
name: 'vendor',
|
|
68
|
-
minChunks: 1,
|
|
69
|
-
priority: 10
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
runtimeChunk: {
|
|
74
|
-
name: 'manifest'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
};
|
|
1
|
+
const merge = require('webpack-merge');
|
|
2
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
3
|
+
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
|
|
4
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
|
+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
6
|
+
const safePostCssParser = require('postcss-safe-parser');
|
|
7
|
+
const baseConfig = require('./webpack.base');
|
|
8
|
+
const { getProjectPath, deleteFolders } = require('../common/utils');
|
|
9
|
+
|
|
10
|
+
module.exports = function(appConfig, extendEnv) {
|
|
11
|
+
const outputPath = getProjectPath(appConfig.buildOutput.path);
|
|
12
|
+
deleteFolders(outputPath);
|
|
13
|
+
|
|
14
|
+
return merge(baseConfig(true, appConfig, extendEnv), {
|
|
15
|
+
// 打包的入口文件
|
|
16
|
+
entry: getProjectPath(appConfig.buildEntry),
|
|
17
|
+
// 打包的出口
|
|
18
|
+
output: {
|
|
19
|
+
publicPath: appConfig.buildOutput.publicPath || '/',
|
|
20
|
+
path: outputPath,
|
|
21
|
+
// 入口文件生产的js
|
|
22
|
+
filename: `js/[name].chunk.js?v=${extendEnv.version}`,
|
|
23
|
+
// 非入口文件生产的js
|
|
24
|
+
chunkFilename: `js/[name].chunk.js?v=${extendEnv.version}`
|
|
25
|
+
},
|
|
26
|
+
node: {
|
|
27
|
+
fs: 'empty'
|
|
28
|
+
},
|
|
29
|
+
plugins: [
|
|
30
|
+
new ScriptExtHtmlWebpackPlugin({
|
|
31
|
+
defaultAttribute: 'async',
|
|
32
|
+
preload: /\.js\?v=/
|
|
33
|
+
})
|
|
34
|
+
],
|
|
35
|
+
optimization: {
|
|
36
|
+
concatenateModules: true,
|
|
37
|
+
minimizer: [
|
|
38
|
+
// 压缩js
|
|
39
|
+
new TerserPlugin({
|
|
40
|
+
cache: true,
|
|
41
|
+
parallel: true,
|
|
42
|
+
sourceMap: true
|
|
43
|
+
}),
|
|
44
|
+
|
|
45
|
+
// 压缩css
|
|
46
|
+
new OptimizeCSSAssetsPlugin({
|
|
47
|
+
cssProcessorOptions: {
|
|
48
|
+
parser: safePostCssParser,
|
|
49
|
+
map: {
|
|
50
|
+
inline: false,
|
|
51
|
+
annotation: false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
],
|
|
56
|
+
splitChunks: {
|
|
57
|
+
chunks: 'initial',
|
|
58
|
+
minSize: 0,
|
|
59
|
+
maxAsyncRequests: 5,
|
|
60
|
+
maxInitialRequests: 3,
|
|
61
|
+
automaticNameDelimiter: '~',
|
|
62
|
+
name: true,
|
|
63
|
+
cacheGroups: {
|
|
64
|
+
vendor: {
|
|
65
|
+
test: /[\\/]node_modules[\\/]/,
|
|
66
|
+
chunks: 'initial',
|
|
67
|
+
name: 'vendor',
|
|
68
|
+
minChunks: 1,
|
|
69
|
+
priority: 10
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
runtimeChunk: {
|
|
74
|
+
name: 'manifest'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
package/ssrConfig/build.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
const webpack = require('webpack');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const appConfig = require('../common/appConfig');
|
|
4
|
-
const { runCallback } = require('../common/build');
|
|
5
|
-
const { getProjectPath, deleteFolders } = require('../common/utils');
|
|
6
|
-
const getEnvironmentInfo = require('../common/extendEnv');
|
|
7
|
-
const clientConfigFactory = require('./webpack.prod.client');
|
|
8
|
-
const serverConfigFactory = require('./webpack.prod.server');
|
|
9
|
-
|
|
10
|
-
process.env.BABEL_ENV = 'production';
|
|
11
|
-
process.env.NODE_ENV = 'production';
|
|
12
|
-
|
|
13
|
-
process.on('unhandledRejection', err => {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
15
|
-
throw err;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const extendEnv = getEnvironmentInfo();
|
|
19
|
-
|
|
20
|
-
function build() {
|
|
21
|
-
const buildClientOutput = getProjectPath(appConfig.buildClientOutput.path);
|
|
22
|
-
deleteFolders(buildClientOutput);
|
|
23
|
-
|
|
24
|
-
const buildServerOutput = getProjectPath(appConfig.buildServerOutput.path);
|
|
25
|
-
deleteFolders(buildServerOutput);
|
|
26
|
-
|
|
27
|
-
const clientConfig = clientConfigFactory(appConfig, extendEnv);
|
|
28
|
-
const serverConfig = serverConfigFactory(appConfig, extendEnv);
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.log(chalk.green('Creating an optimized production build...'));
|
|
31
|
-
const clientCompiler = webpack(clientConfig);
|
|
32
|
-
const serverCompiler = webpack(serverConfig);
|
|
33
|
-
const clientCompilerPromise = new Promise((resolve, reject) => {
|
|
34
|
-
clientCompiler.run(runCallback(resolve, reject));
|
|
35
|
-
});
|
|
36
|
-
const serverCompilerPromise = new Promise((resolve, reject) => {
|
|
37
|
-
serverCompiler.run(runCallback(resolve, reject));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return Promise.all([clientCompilerPromise, serverCompilerPromise]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
build()
|
|
44
|
-
.then(
|
|
45
|
-
([clientInfo, serverInfo]) => {
|
|
46
|
-
if (clientInfo.warnings.length || serverInfo.warnings.length) {
|
|
47
|
-
// eslint-disable-next-line no-console
|
|
48
|
-
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.log(clientInfo.warnings.join('\n\n'));
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
|
-
console.log(serverInfo.warnings.join('\n\n'));
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.log(
|
|
55
|
-
`\nSearch for the ${chalk.underline(
|
|
56
|
-
chalk.yellow('keywords')
|
|
57
|
-
)} to learn more about each warning.`
|
|
58
|
-
);
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.log(
|
|
61
|
-
`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`
|
|
62
|
-
);
|
|
63
|
-
} else {
|
|
64
|
-
// eslint-disable-next-line no-console
|
|
65
|
-
console.log(chalk.green('Compiled successfully.\n'));
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
err => {
|
|
69
|
-
// eslint-disable-next-line no-console
|
|
70
|
-
console.log(chalk.red('Failed to compile.\n'));
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.log(err);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
)
|
|
76
|
-
.catch(err => {
|
|
77
|
-
// eslint-disable-next-line no-console
|
|
78
|
-
console.log(chalk.red('Failed to compile.\n'));
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
|
-
console.log(err);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
});
|
|
1
|
+
const webpack = require('webpack');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const appConfig = require('../common/appConfig');
|
|
4
|
+
const { runCallback } = require('../common/build');
|
|
5
|
+
const { getProjectPath, deleteFolders } = require('../common/utils');
|
|
6
|
+
const getEnvironmentInfo = require('../common/extendEnv');
|
|
7
|
+
const clientConfigFactory = require('./webpack.prod.client');
|
|
8
|
+
const serverConfigFactory = require('./webpack.prod.server');
|
|
9
|
+
|
|
10
|
+
process.env.BABEL_ENV = 'production';
|
|
11
|
+
process.env.NODE_ENV = 'production';
|
|
12
|
+
|
|
13
|
+
process.on('unhandledRejection', err => {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
15
|
+
throw err;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const extendEnv = getEnvironmentInfo();
|
|
19
|
+
|
|
20
|
+
function build() {
|
|
21
|
+
const buildClientOutput = getProjectPath(appConfig.buildClientOutput.path);
|
|
22
|
+
deleteFolders(buildClientOutput);
|
|
23
|
+
|
|
24
|
+
const buildServerOutput = getProjectPath(appConfig.buildServerOutput.path);
|
|
25
|
+
deleteFolders(buildServerOutput);
|
|
26
|
+
|
|
27
|
+
const clientConfig = clientConfigFactory(appConfig, extendEnv);
|
|
28
|
+
const serverConfig = serverConfigFactory(appConfig, extendEnv);
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(chalk.green('Creating an optimized production build...'));
|
|
31
|
+
const clientCompiler = webpack(clientConfig);
|
|
32
|
+
const serverCompiler = webpack(serverConfig);
|
|
33
|
+
const clientCompilerPromise = new Promise((resolve, reject) => {
|
|
34
|
+
clientCompiler.run(runCallback(resolve, reject));
|
|
35
|
+
});
|
|
36
|
+
const serverCompilerPromise = new Promise((resolve, reject) => {
|
|
37
|
+
serverCompiler.run(runCallback(resolve, reject));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return Promise.all([clientCompilerPromise, serverCompilerPromise]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
build()
|
|
44
|
+
.then(
|
|
45
|
+
([clientInfo, serverInfo]) => {
|
|
46
|
+
if (clientInfo.warnings.length || serverInfo.warnings.length) {
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log(clientInfo.warnings.join('\n\n'));
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.log(serverInfo.warnings.join('\n\n'));
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log(
|
|
55
|
+
`\nSearch for the ${chalk.underline(
|
|
56
|
+
chalk.yellow('keywords')
|
|
57
|
+
)} to learn more about each warning.`
|
|
58
|
+
);
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log(
|
|
61
|
+
`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
err => {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.log(err);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
.catch(err => {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
console.log(err);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|