@jeffchi/logger 3.0.1-alpha.5 → 3.1.0-rc.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.
Files changed (2) hide show
  1. package/README.md +96 -2
  2. package/package.json +3 -7
package/README.md CHANGED
@@ -28,11 +28,11 @@ A log print output javascript tool library that can be used at the front and bac
28
28
  ### 使用 npm 或 yarn 安装
29
29
 
30
30
  ```bash
31
- $ npm install @jeffchi/logger --save
31
+ npm install @jeffchi/logger --save
32
32
  ```
33
33
 
34
34
  ```bash
35
- $ yarn add @jeffchi/logger
35
+ yarn add @jeffchi/logger
36
36
  ```
37
37
 
38
38
  如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。
@@ -152,6 +152,100 @@ export interface ILogOptions {
152
152
  | push | 用指定 message 提交代码并推送至远程 |
153
153
  | release [`<verson>`\|`patch`\|`minor`\|`major`] -- [`--alpha`\|`--beta`\|`--rc`] [`--all`] [`--otp code`] | 生成新的 `主`\|`次`\|`批` 版本号,推送远程仓库后,并发布至 npm 仓 <blockquote><li> --alpha: 预发布内部版本</li><li> --beta: 预发布公测版本</li><li> -rc: 预发布候选版本</li><li> -all: 提交全部修改</li><li> -otp `<code>`: 如果指定一次性口令,则直接发布到 npm 中心仓,否则不发布</li></blockquote> |
154
154
 
155
+ ## 已知问题及解决方案
156
+
157
+ ### 1 Webpack5 前端项目报错
158
+
159
+ ```bash
160
+ Failed to compile.
161
+
162
+ Module not found: Error: Can't resolve 'fs' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
163
+ ERROR in ./node_modules/@jeffchi/logger/lib/index.mjs 1252:133-145
164
+ Module not found: Error: Can't resolve 'fs' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
165
+
166
+ ERROR in ./node_modules/@jeffchi/logger/lib/index.mjs 1252:147-161
167
+ Module not found: Error: Can't resolve 'path' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
168
+
169
+ BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
170
+ This is no longer the case. Verify if you need this module and configure a polyfill for it.
171
+
172
+ If you want to include a polyfill, you need to:
173
+ - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
174
+ - install 'path-browserify'
175
+ If you don't want to include a polyfill, you can use an empty module like this:
176
+ resolve.fallback: { "path": false }
177
+
178
+ webpack compiled with 2 errors
179
+ No issues found.
180
+ ```
181
+
182
+ #### 原因
183
+
184
+ `@jeffchi/logger` 是一个前后端能用的 npm 库,在后端使用时需要写入日志文件,需要依赖于`fs` 和 `path` 两个 node 核心库,在前端,则不需要. 早前 webpack4 会在构建 bundle 为 node.js 核心库附加庞大的 polyfills,对于前端项目,大部分的 polyfills 都不是必须的,webpack5 现在要停止这项工作,在模块构建时不再自动引入 polyfills,以减小打包体积.
185
+
186
+ #### 解决方案
187
+
188
+ ##### ~~1. 安装 path-browserify~~
189
+
190
+ ```bash
191
+ npm install path-browserify --save
192
+ # or
193
+ yarn add path-browserify
194
+ ```
195
+
196
+ > 因为前端项目不需要写放日志文件,所以此处可以跳过这一步
197
+
198
+ ##### 2. 配置 webpack
199
+
200
+ ```js
201
+ // webpack.config.js
202
+ resolve: {
203
+ fallback: {
204
+ // 如果需要,则引入path-browserify
205
+ // path: require.resolve("path-browserify"),
206
+ path: false;
207
+ }
208
+ }
209
+ ```
210
+
211
+ ###### 2.1craco
212
+
213
+ 如果你使用的是 craco:
214
+
215
+ ```js
216
+ module.exports = {
217
+ webpack: {
218
+ alias: {
219
+ // alias...
220
+ },
221
+
222
+ configure: (config) => {
223
+ const { resolve = {} } = config;
224
+ resolve.fallback = { ...(resolve.fallback || {}), fs: false, path: false };
225
+ resolve.fallback.path = false;
226
+ return { ...config, resolve };
227
+ },
228
+ },
229
+ plugins: [
230
+ // plugins...
231
+ ],
232
+ };
233
+ ```
234
+
235
+ ##### 3.修改 package.json
236
+
237
+ ```json
238
+ "browser":{
239
+ "path":false,
240
+ "fs":false
241
+ },
242
+ "dependencies":{
243
+ // ...
244
+ }
245
+ ```
246
+
247
+ > 此步骤非必须
248
+
155
249
  ## License
156
250
 
157
251
  MIT
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@jeffchi/logger",
3
- "version": "3.0.1-alpha.5",
3
+ "version": "3.1.0-rc.0",
4
4
  "main": "lib/index.cjs",
5
5
  "module": "lib/index.mjs",
6
+ "browser": "lib/index.cjs",
6
7
  "types": "lib/index.d.ts",
7
8
  "type": "module",
8
9
  "description": "A log print output javascript tool library that can be used at the front and back ends",
@@ -33,7 +34,7 @@
33
34
  "format": "prettier --write \"src/**/*.ts\"",
34
35
  "lint": "tslint -p tsconfig.json",
35
36
  "test": "jest --config jestconfig.json",
36
- "prepush": "git add .",
37
+ "prepush": "npm run lint && npm run format && git add -A .",
37
38
  "push": "git commit -m",
38
39
  "postpush": "git push",
39
40
  "prepublishOnly": "npm run test main && npm run lint",
@@ -53,11 +54,6 @@
53
54
  "lib",
54
55
  "*.d.ts"
55
56
  ],
56
- "standard-version": {
57
- "scripts": {
58
- "prerelease": "npm run lint && npm run format && git add -A ."
59
- }
60
- },
61
57
  "peerDependencies": {
62
58
  "date-fns": "^2.29.3"
63
59
  },