@autobest-ui/scripts 0.0.4 → 0.1.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.
@@ -1,144 +1,144 @@
1
- const nodemon = require('nodemon');
2
- const open = require('open');
3
- const webpack = require('webpack');
4
- const appConfig = require('../common/appConfig');
5
- const getEnvironmentInfo = require('../common/extendEnv');
6
- const clientConfigFactory = require('./webpack.dev.client');
7
- const serverConfigFactory = require('./webpack.dev.server');
8
- const { getProjectPath, parseArgsToJson } = require('../common/utils');
9
-
10
- const extendEnv = getEnvironmentInfo(true);
11
- const clientConfig = clientConfigFactory(appConfig, extendEnv);
12
- const serverConfig = serverConfigFactory(appConfig, extendEnv);
13
-
14
- const PORT = process.env.PORT || parseArgsToJson.port || appConfig.hotSsrDefaultPort;
15
- const hotSsrOpenPath = appConfig.hotSsrOpenPath ? appConfig.hotSsrOpenPath : '';
16
-
17
- process.env.BABEL_ENV = 'development';
18
- process.env.NODE_ENV = 'development';
19
-
20
- const options = {
21
- // 配置文件
22
- script: getProjectPath(appConfig.hotSsrRunPath),
23
- restartable: 're',
24
- verbose: true,
25
- delay: 3000,
26
- watch: appConfig.hotSsrWatch,
27
- env: {
28
- SERVER_PORT: appConfig.hotSsrDefaultPort,
29
- SERVER_RUN: 'NODE',
30
- ...extendEnv.raw
31
- }
32
- };
33
-
34
- const clientCompiler = webpack(clientConfig);
35
- const serverCompiler = webpack(serverConfig);
36
-
37
- let isOpened = false;
38
-
39
- function openServer() {
40
- nodemon(options)
41
- .on('start', () => {
42
- // 启动时的事件
43
- // eslint-disable-next-line no-console
44
- console.log('Server app has started');
45
- if (!isOpened) {
46
- open(`http://localhost:${PORT}${hotSsrOpenPath}`);
47
- isOpened = true;
48
- }
49
- })
50
- .on('quit', () => {
51
- // 退出时的事件
52
- // eslint-disable-next-line no-console
53
- console.log('Server app has quit');
54
- process.exit();
55
- })
56
- .on('restart', () => {
57
- // 重启时的事件
58
- // eslint-disable-next-line no-console
59
- console.log('Server app has restarted');
60
- });
61
- }
62
-
63
- function run() {
64
- const compiler = new Promise((resolve, reject) => {
65
- let clientWatched = false;
66
- let serverWatched = false;
67
- let isResolved = false;
68
-
69
- function completeAndResolve() {
70
- if (clientWatched && serverWatched && !isResolved) {
71
- isResolved = true;
72
- return resolve();
73
- }
74
- return null;
75
- }
76
-
77
- function watchingHandler(err, stats) {
78
- const info = stats.toJson({
79
- assets: false,
80
- hash: false,
81
- colors: false,
82
- warningsFilter: warn => warn.indexOf('Conflicting order between:') > -1
83
- });
84
- if (stats.hasErrors()) {
85
- // eslint-disable-next-line no-console
86
- info.errors.forEach(item => console.log(item));
87
- }
88
-
89
- if (stats.hasWarnings()) {
90
- // eslint-disable-next-line no-console
91
- info.warnings.forEach(item => console.log(item));
92
- }
93
- }
94
-
95
- const clientWatching = clientCompiler.watch(
96
- {
97
- ignored: /node_modules/,
98
- aggregateTimeout: 600
99
- },
100
- // eslint-disable-next-line consistent-return
101
- (err, stats) => {
102
- if (err) {
103
- // eslint-disable-next-line no-console
104
- console.log(err);
105
- clientWatching.invalidate();
106
- return reject();
107
- }
108
- watchingHandler(err, stats);
109
-
110
- clientWatched = true;
111
- completeAndResolve();
112
- }
113
- );
114
- const serverWatching = serverCompiler.watch(
115
- {
116
- ignored: /node_modules/,
117
- aggregateTimeout: 600
118
- },
119
- // eslint-disable-next-line consistent-return
120
- (err, stats) => {
121
- if (err) {
122
- // eslint-disable-next-line no-console
123
- console.log(err);
124
- serverWatching.invalidate();
125
- return reject();
126
- }
127
-
128
- watchingHandler(err, stats);
129
-
130
- serverWatched = true;
131
- completeAndResolve();
132
- }
133
- );
134
- });
135
-
136
- compiler
137
- .then(() => {
138
- openServer();
139
- })
140
- // eslint-disable-next-line no-console
141
- .catch(error => console.log(error));
142
- }
143
-
144
- run();
1
+ const nodemon = require('nodemon');
2
+ const open = require('open');
3
+ const webpack = require('webpack');
4
+ const appConfig = require('../common/appConfig');
5
+ const getEnvironmentInfo = require('../common/extendEnv');
6
+ const clientConfigFactory = require('./webpack.dev.client');
7
+ const serverConfigFactory = require('./webpack.dev.server');
8
+ const { getProjectPath, parseArgsToJson } = require('../common/utils');
9
+
10
+ const extendEnv = getEnvironmentInfo(true);
11
+ const clientConfig = clientConfigFactory(appConfig, extendEnv);
12
+ const serverConfig = serverConfigFactory(appConfig, extendEnv);
13
+
14
+ const PORT = process.env.PORT || parseArgsToJson.port || appConfig.hotSsrDefaultPort;
15
+ const hotSsrOpenPath = appConfig.hotSsrOpenPath ? appConfig.hotSsrOpenPath : '';
16
+
17
+ process.env.BABEL_ENV = 'development';
18
+ process.env.NODE_ENV = 'development';
19
+
20
+ const options = {
21
+ // 配置文件
22
+ script: getProjectPath(appConfig.hotSsrRunPath),
23
+ restartable: 're',
24
+ verbose: true,
25
+ delay: 3000,
26
+ watch: appConfig.hotSsrWatch,
27
+ env: {
28
+ SERVER_PORT: PORT,
29
+ SERVER_RUN: 'NODE',
30
+ ...extendEnv.raw
31
+ }
32
+ };
33
+
34
+ const clientCompiler = webpack(clientConfig);
35
+ const serverCompiler = webpack(serverConfig);
36
+
37
+ let isOpened = false;
38
+
39
+ function openServer() {
40
+ nodemon(options)
41
+ .on('start', () => {
42
+ // 启动时的事件
43
+ // eslint-disable-next-line no-console
44
+ console.log('Server app has started');
45
+ if (!isOpened) {
46
+ open(`http://localhost:${PORT}${hotSsrOpenPath}`);
47
+ isOpened = true;
48
+ }
49
+ })
50
+ .on('quit', () => {
51
+ // 退出时的事件
52
+ // eslint-disable-next-line no-console
53
+ console.log('Server app has quit');
54
+ process.exit();
55
+ })
56
+ .on('restart', () => {
57
+ // 重启时的事件
58
+ // eslint-disable-next-line no-console
59
+ console.log('Server app has restarted');
60
+ });
61
+ }
62
+
63
+ function run() {
64
+ const compiler = new Promise((resolve, reject) => {
65
+ let clientWatched = false;
66
+ let serverWatched = false;
67
+ let isResolved = false;
68
+
69
+ function completeAndResolve() {
70
+ if (clientWatched && serverWatched && !isResolved) {
71
+ isResolved = true;
72
+ return resolve();
73
+ }
74
+ return null;
75
+ }
76
+
77
+ function watchingHandler(err, stats) {
78
+ const info = stats.toJson({
79
+ assets: false,
80
+ hash: false,
81
+ colors: false,
82
+ warningsFilter: warn => warn.indexOf('Conflicting order between:') > -1
83
+ });
84
+ if (stats.hasErrors()) {
85
+ // eslint-disable-next-line no-console
86
+ info.errors.forEach(item => console.log(item));
87
+ }
88
+
89
+ if (stats.hasWarnings()) {
90
+ // eslint-disable-next-line no-console
91
+ info.warnings.forEach(item => console.log(item));
92
+ }
93
+ }
94
+
95
+ const clientWatching = clientCompiler.watch(
96
+ {
97
+ ignored: /node_modules/,
98
+ aggregateTimeout: 600
99
+ },
100
+ // eslint-disable-next-line consistent-return
101
+ (err, stats) => {
102
+ if (err) {
103
+ // eslint-disable-next-line no-console
104
+ console.log(err);
105
+ clientWatching.invalidate();
106
+ return reject();
107
+ }
108
+ watchingHandler(err, stats);
109
+
110
+ clientWatched = true;
111
+ completeAndResolve();
112
+ }
113
+ );
114
+ const serverWatching = serverCompiler.watch(
115
+ {
116
+ ignored: /node_modules/,
117
+ aggregateTimeout: 600
118
+ },
119
+ // eslint-disable-next-line consistent-return
120
+ (err, stats) => {
121
+ if (err) {
122
+ // eslint-disable-next-line no-console
123
+ console.log(err);
124
+ serverWatching.invalidate();
125
+ return reject();
126
+ }
127
+
128
+ watchingHandler(err, stats);
129
+
130
+ serverWatched = true;
131
+ completeAndResolve();
132
+ }
133
+ );
134
+ });
135
+
136
+ compiler
137
+ .then(() => {
138
+ openServer();
139
+ })
140
+ // eslint-disable-next-line no-console
141
+ .catch(error => console.log(error));
142
+ }
143
+
144
+ run();
@@ -1,4 +1,4 @@
1
- const webpackFactory = require('./webpack.dev');
2
- const openStartRun = require('../common/start');
3
-
4
- openStartRun(webpackFactory);
1
+ const webpackFactory = require('./webpack.dev');
2
+ const openStartRun = require('../common/start');
3
+
4
+ openStartRun(webpackFactory);
@@ -1,60 +1,46 @@
1
- const webpack = require('webpack');
2
- const merge = require('webpack-merge');
3
- const path = require('path');
4
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5
- const webpackCommon = require('../common/webpack.common');
6
-
7
- module.exports = (appConfig, extendEnv, { isServer, isHotServer, isSetCommonAlias, isProd }) => {
8
- const result = {
9
- plugins: [],
10
- module: {
11
- rules: []
12
- }
13
- };
14
- if ((isProd || isHotServer) && !isServer) {
15
- result.plugins.push(
16
- // modules Id 随机数导致缓存失效
17
- new webpack.HashedModuleIdsPlugin(),
18
- // 解决新旧版本迭代时,google cache 旧版不能正常运行js
19
- // 通过指定chunk name而不是随机数
20
- new webpack.NamedChunksPlugin(chunk => {
21
- if (chunk.name) {
22
- return chunk.name;
23
- }
24
-
25
- // eslint-disable-next-line no-underscore-dangle
26
- return [...chunk._modules]
27
- .map(m =>
28
- path.relative(m.context, m.userRequest.substring(0, m.userRequest.lastIndexOf('.')))
29
- )
30
- .join('_');
31
- }),
32
- new MiniCssExtractPlugin({
33
- // filename: isHotServer ? 'css/[name].css' : `css/[name].css?v=${env.version}`,
34
- // 采用AMP 直接 把css 填充到html
35
- filename: isHotServer ? 'css/[name].css' : 'css/[name][contenthash].css',
36
- allChunks: !isHotServer,
37
- ignoreOrder: true
38
- })
39
- );
40
- }
41
-
42
- if (isSetCommonAlias) {
43
- // 替换文件路径
44
- result.module.rules.unshift({
45
- test: /\.(js|ts|tsx)$/,
46
- loader: '@autobest-ui/replace-loader',
47
- options: {
48
- list: [
49
- {
50
- pattern: '@autobest-ui/auto-parts-prime/lib',
51
- target: '@autobest-ui/auto-parts-prime/src',
52
- modifiers: 'g'
53
- }
54
- ]
55
- }
56
- });
57
- }
58
-
59
- return merge(webpackCommon(appConfig, extendEnv, { isProd, isServer, isHotServer }), result);
60
- };
1
+ const webpack = require('webpack');
2
+ const merge = require('webpack-merge');
3
+ const path = require('path');
4
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5
+ const webpackCommon = require('../common/webpack.common');
6
+
7
+ module.exports = (appConfig, extendEnv, { isServer, isHotServer, isSetCommonAlias, isProd }) => {
8
+ const result = {
9
+ plugins: [],
10
+ module: {
11
+ rules: []
12
+ }
13
+ };
14
+ if ((isProd || isHotServer) && !isServer) {
15
+ result.plugins.push(
16
+ // modules Id 随机数导致缓存失效
17
+ new webpack.HashedModuleIdsPlugin(),
18
+ // 解决新旧版本迭代时,google cache 旧版不能正常运行js
19
+ // 通过指定chunk name而不是随机数
20
+ new webpack.NamedChunksPlugin(chunk => {
21
+ if (chunk.name) {
22
+ return chunk.name;
23
+ }
24
+
25
+ // eslint-disable-next-line no-underscore-dangle
26
+ return [...chunk._modules]
27
+ .map(m =>
28
+ path.relative(m.context, m.userRequest.substring(0, m.userRequest.lastIndexOf('.')))
29
+ )
30
+ .join('_');
31
+ }),
32
+ new MiniCssExtractPlugin({
33
+ // filename: isHotServer ? 'css/[name].css' : `css/[name].css?v=${env.version}`,
34
+ // 采用AMP 直接 把css 填充到html
35
+ filename: isHotServer ? 'css/[name].css' : 'css/[name][contenthash].css',
36
+ allChunks: !isHotServer,
37
+ ignoreOrder: true
38
+ })
39
+ );
40
+ }
41
+
42
+ return merge(
43
+ webpackCommon(appConfig, extendEnv, { isProd, isServer, isHotServer, isSetCommonAlias }),
44
+ result
45
+ );
46
+ };
@@ -1,31 +1,31 @@
1
- const merge = require('webpack-merge');
2
- const LoadablePlugin = require('@loadable/webpack-plugin');
3
- const baseConfig = require('./webpack.base');
4
- const { getProjectPath } = require('../common/utils');
5
-
6
- module.exports = function(appConfig, extendEnv) {
7
- return merge(
8
- baseConfig(appConfig, extendEnv, {
9
- isServer: false,
10
- isHotServer: true,
11
- isSetCommonAlias: true,
12
- isProd: false
13
- }),
14
- {
15
- // 入口文件
16
- entry: getProjectPath(appConfig.hotSsrClientEntry),
17
- node: {
18
- fs: 'empty'
19
- },
20
- // 输出信息
21
- output: {
22
- // 输出文件路径
23
- path: getProjectPath(appConfig.hotSsrClientOutput.path),
24
- publicPath: appConfig.hotSsrClientOutput.publicPath || '/',
25
- filename: 'js/[name].js',
26
- chunkFilename: 'js/[name].js'
27
- },
28
- plugins: [new LoadablePlugin()]
29
- }
30
- );
31
- };
1
+ const merge = require('webpack-merge');
2
+ const LoadablePlugin = require('@loadable/webpack-plugin');
3
+ const baseConfig = require('./webpack.base');
4
+ const { getProjectPath } = require('../common/utils');
5
+
6
+ module.exports = function(appConfig, extendEnv) {
7
+ return merge(
8
+ baseConfig(appConfig, extendEnv, {
9
+ isServer: false,
10
+ isHotServer: true,
11
+ isSetCommonAlias: true,
12
+ isProd: false
13
+ }),
14
+ {
15
+ // 入口文件
16
+ entry: getProjectPath(appConfig.hotSsrClientEntry),
17
+ node: {
18
+ fs: 'empty'
19
+ },
20
+ // 输出信息
21
+ output: {
22
+ // 输出文件路径
23
+ path: getProjectPath(appConfig.hotSsrClientOutput.path),
24
+ publicPath: appConfig.hotSsrClientOutput.publicPath || '/',
25
+ filename: 'js/[name].js',
26
+ chunkFilename: 'js/[name].js'
27
+ },
28
+ plugins: [new LoadablePlugin()]
29
+ }
30
+ );
31
+ };
@@ -1,58 +1,58 @@
1
- const merge = require('webpack-merge');
2
- const HtmlWebpackPlugin = require('html-webpack-plugin');
3
- const ip = require('ip');
4
- const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
5
- const baseConfig = require('./webpack.base');
6
- const { getProjectPath } = require('../common/utils');
7
-
8
- const HOST = process.env.HOST || ip.address() || 'localhost';
9
-
10
- module.exports = function(appConfig, extendEnv) {
11
- return merge(
12
- baseConfig(appConfig, extendEnv, {
13
- isServer: false,
14
- isHotServer: false,
15
- isSetCommonAlias: true,
16
- isProd: false
17
- }),
18
- {
19
- entry: getProjectPath(appConfig.startEntry),
20
- output: {
21
- publicPath: appConfig.startOutput.publicPath || '/',
22
- path: appConfig.startOutput.path,
23
- pathinfo: true,
24
- futureEmitAssets: true,
25
- filename: 'bundle.js',
26
- chunkFilename: '[name].chunk.js'
27
- },
28
- plugins: [
29
- // 相关配置文档:https://github.com/geowarin/friendly-errors-webpack-plugin
30
- new FriendlyErrorsPlugin({
31
- compilationSuccessInfo: {
32
- messages: [
33
- `localhost运行链接: http://localhost:${appConfig.port}${appConfig.startOpenPath}\n`,
34
- `ip运行链接: http://${HOST}:${appConfig.port}${appConfig.startOpenPath}\n`
35
- ]
36
- },
37
- onErrors: null,
38
- clearConsole: true
39
- }),
40
- new HtmlWebpackPlugin({
41
- inject: true,
42
- template: getProjectPath(appConfig.htmlPluginTemplate)
43
- })
44
- ],
45
- node: {
46
- fs: 'empty'
47
- },
48
- optimization: {
49
- minimize: false,
50
- splitChunks: {
51
- chunks: 'all',
52
- name: false
53
- },
54
- runtimeChunk: true
55
- }
56
- }
57
- );
58
- };
1
+ const merge = require('webpack-merge');
2
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
3
+ const ip = require('ip');
4
+ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
5
+ const baseConfig = require('./webpack.base');
6
+ const { getProjectPath } = require('../common/utils');
7
+
8
+ const HOST = process.env.HOST || ip.address() || 'localhost';
9
+
10
+ module.exports = function(appConfig, extendEnv) {
11
+ return merge(
12
+ baseConfig(appConfig, extendEnv, {
13
+ isServer: false,
14
+ isHotServer: false,
15
+ isSetCommonAlias: true,
16
+ isProd: false
17
+ }),
18
+ {
19
+ entry: getProjectPath(appConfig.startEntry),
20
+ output: {
21
+ publicPath: appConfig.startOutput.publicPath || '/',
22
+ path: appConfig.startOutput.path,
23
+ pathinfo: true,
24
+ futureEmitAssets: true,
25
+ filename: 'bundle.js',
26
+ chunkFilename: '[name].chunk.js'
27
+ },
28
+ plugins: [
29
+ // 相关配置文档:https://github.com/geowarin/friendly-errors-webpack-plugin
30
+ new FriendlyErrorsPlugin({
31
+ compilationSuccessInfo: {
32
+ messages: [
33
+ `localhost运行链接: http://localhost:${appConfig.port}${appConfig.startOpenPath}\n`,
34
+ `ip运行链接: http://${HOST}:${appConfig.port}${appConfig.startOpenPath}\n`
35
+ ]
36
+ },
37
+ onErrors: null,
38
+ clearConsole: true
39
+ }),
40
+ new HtmlWebpackPlugin({
41
+ inject: true,
42
+ template: getProjectPath(appConfig.htmlPluginTemplate)
43
+ })
44
+ ],
45
+ node: {
46
+ fs: 'empty'
47
+ },
48
+ optimization: {
49
+ minimize: false,
50
+ splitChunks: {
51
+ chunks: 'all',
52
+ name: false
53
+ },
54
+ runtimeChunk: true
55
+ }
56
+ }
57
+ );
58
+ };