@autobest-ui/scripts 0.0.3 → 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.
@@ -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: `static/js/[name].chunk.js?v=${extendEnv.version}`,
23
- // 非入口文件生产的js
24
- chunkFilename: `static/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
+ };
@@ -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
+ });