@autobest-ui/scripts 1.1.1 → 1.3.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 +30 -0
- package/common/start.js +11 -2
- package/common/webpack.common.js +4 -3
- package/package.json +2 -2
- package/spaConfig/webpack.prod.js +21 -12
package/README.md
CHANGED
|
@@ -118,3 +118,33 @@ module.exports = function(
|
|
|
118
118
|
该方式,主要应用于启动程序前,自定义环境变量,主要用于get**EnvConfig()方法的多样性。
|
|
119
119
|
|
|
120
120
|
例如: `cross-env REACT_APP_ENV=local react-ssr start`
|
|
121
|
+
|
|
122
|
+
#### 背景图片问题
|
|
123
|
+
推荐把静态资源放到静态库,并使用sass环境变量`$env`进行本地调试,若想使用本地文件,需特殊处理。
|
|
124
|
+
|
|
125
|
+
- scss环境变量
|
|
126
|
+
```scss
|
|
127
|
+
// 其中 $env = process.env.NODE_ENV, 满足background-image链接不全、区分本地与线上样式等需求。
|
|
128
|
+
if($env == 'development','为true的样式', ‘为false的样式’)
|
|
129
|
+
// 例子
|
|
130
|
+
$AssetBaseUrl: 'https://assets-web.dev.autobestdevops.com';
|
|
131
|
+
$AssetCommonPath: '/common-uiasset';
|
|
132
|
+
$AssetWwwPath: '/www-uiasset';
|
|
133
|
+
|
|
134
|
+
@mixin getBgImgFromCommon($url) {
|
|
135
|
+
background-image: if($env == 'development', url($AssetBaseUrl + $AssetCommonPath + $url), url($AssetCommonPath + $url));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@mixin getBgImgFromWww($url) {
|
|
139
|
+
background-image: if($env == 'development', url($AssetBaseUrl + $AssetWwwPath + $url), url($AssetWwwPath + $url));
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- 使用本地文件注意事项
|
|
144
|
+
```scss
|
|
145
|
+
// background image 不解析以"http、https"开头或者/common-uiasset/|/wwwasset/|/onlineasset/开头的静态资源, 例如:'/common-uiasset/img.png'
|
|
146
|
+
// 所以本地静态资源需要特别注意,不能创建/common-uiasset/|/wwwasset/|/onlineasset/文件夹
|
|
147
|
+
.live-chat {
|
|
148
|
+
background: url('imgs/图片名.resolving.png') 0 center no-repeat;
|
|
149
|
+
}
|
|
150
|
+
```
|
package/common/start.js
CHANGED
|
@@ -45,14 +45,23 @@ function openStartRun(webpackFactory) {
|
|
|
45
45
|
const config = webpackFactory({ ...appConfig, port: PORT, startOpenPath }, extendEnv);
|
|
46
46
|
const compiler = webpack(config);
|
|
47
47
|
const server = new WebpackDevServer(options, compiler);
|
|
48
|
+
let hasOpenBrowser = false;
|
|
49
|
+
|
|
50
|
+
// 添加钩子函数,弹出浏览器
|
|
51
|
+
compiler.hooks.done.tap('OpenBrowser', () => {
|
|
52
|
+
if (!hasOpenBrowser) {
|
|
53
|
+
hasOpenBrowser = true;
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
open(`http://localhost:${PORT}${startOpenPath}`);
|
|
56
|
+
}, 600);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
48
59
|
|
|
49
60
|
server.startCallback(err => {
|
|
50
61
|
if (err) {
|
|
51
62
|
// eslint-disable-next-line no-console
|
|
52
63
|
console.log(err);
|
|
53
|
-
return;
|
|
54
64
|
}
|
|
55
|
-
open(`http://localhost:${PORT}${startOpenPath}`);
|
|
56
65
|
});
|
|
57
66
|
['SIGINT', 'SIGTERM'].forEach(sig => {
|
|
58
67
|
process.on(sig, () => {
|
package/common/webpack.common.js
CHANGED
|
@@ -8,7 +8,8 @@ const appWebpackConfigPath = getProjectPath('/config/app.webpack.js');
|
|
|
8
8
|
|
|
9
9
|
const sassRegex = /\.(scss|sass)$/;
|
|
10
10
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
11
|
-
const
|
|
11
|
+
const imageNotResolvingRegex = /^\/(common-uiasset|wwwasset|onlineasset)\//;
|
|
12
|
+
const httpRegex = /^https?:\/\//;
|
|
12
13
|
|
|
13
14
|
function getStyleLoaders({ isProd, isServer, isHotServer, isSass, moduleOption = {} }) {
|
|
14
15
|
const result = [
|
|
@@ -17,8 +18,8 @@ function getStyleLoaders({ isProd, isServer, isHotServer, isSass, moduleOption =
|
|
|
17
18
|
options: {
|
|
18
19
|
...moduleOption,
|
|
19
20
|
url: {
|
|
20
|
-
// background image
|
|
21
|
-
filter: url =>
|
|
21
|
+
// background image不解析以"http、https"开头或者/common-uiasset/|/wwwasset/|/onlineasset/开头的静态资源, 例如:'/common-uiasset/img.png'
|
|
22
|
+
filter: url => !httpRegex.test(url) && !imageNotResolvingRegex.test(url)
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobest-ui/scripts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "utils for project tools",
|
|
6
6
|
"bin": {
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"webpack-merge": "5.8.0",
|
|
93
93
|
"webpack-node-externals": "3.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "6a50d3def5d2d02802c524f99663347f410762c0"
|
|
96
96
|
}
|
|
@@ -21,6 +21,8 @@ module.exports = function (appConfig, extendEnv) {
|
|
|
21
21
|
chunkFilename: `js/[name].chunk.js?v=${extendEnv.version}`
|
|
22
22
|
},
|
|
23
23
|
optimization: {
|
|
24
|
+
// 在不同的编译中不变的短数字id。有益于长期缓存。在生产模式中会默认开启。
|
|
25
|
+
chunkIds: 'deterministic',
|
|
24
26
|
concatenateModules: true,
|
|
25
27
|
minimizer: [
|
|
26
28
|
// 压缩js
|
|
@@ -49,20 +51,27 @@ module.exports = function (appConfig, extendEnv) {
|
|
|
49
51
|
new CssMinimizerPlugin()
|
|
50
52
|
],
|
|
51
53
|
splitChunks: {
|
|
52
|
-
chunks: '
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
chunks: 'async',
|
|
55
|
+
// 大于3kb才会分割
|
|
56
|
+
minSize: 3072,
|
|
57
|
+
minRemainingSize: 0,
|
|
58
|
+
minChunks: 1,
|
|
59
|
+
// 按需加载时的最大并行请求数。
|
|
60
|
+
maxAsyncRequests: 300,
|
|
61
|
+
// 入口点的最大并行请求数。
|
|
62
|
+
maxInitialRequests: 300,
|
|
63
|
+
enforceSizeThreshold: 50000,
|
|
59
64
|
cacheGroups: {
|
|
60
|
-
|
|
65
|
+
defaultVendors: {
|
|
61
66
|
test: /[\\/]node_modules[\\/]/,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
minChunks: 2,
|
|
68
|
+
priority: -10,
|
|
69
|
+
reuseExistingChunk: true
|
|
70
|
+
},
|
|
71
|
+
default: {
|
|
72
|
+
minChunks: 3,
|
|
73
|
+
priority: -20,
|
|
74
|
+
reuseExistingChunk: true
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
},
|