File tree 2 files changed +14
-5
lines changed
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 35
35
36
36
- ` module.exports = `
37
37
38
- 因打包脚本缺陷问题,不允许使用 ` module.exports = { name } ` 的形式,此形式不能很好的压缩代码
38
+ 因打包脚本缺陷问题,不允许使用 ` module.exports = { name: 'Jackie' } ` 的形式,此形式会发生异常
39
39
40
40
``` javascript
41
41
// ❌
42
+ module .exports = {
43
+ name: ' Jackie' ,
44
+ age: 18
45
+ };
46
+ ```
47
+
48
+ ``` javascript
49
+ // ✅ 可以使用缩写形式
42
50
const name = ' Jackie'
43
51
const age = 18
44
52
47
55
48
56
``` javascript
49
57
// ✅
50
- module . exports .name = ' Jackie'
51
- module . exports .age = 18
58
+ exports .name = ' Jackie'
59
+ exports .age = 18
52
60
```
53
61
54
62
- 工具模块统一使用 ` .module.js ` 为后缀,打包工具会忽略 ` .module.js ` 后缀的文件
Original file line number Diff line number Diff line change @@ -64,8 +64,9 @@ for (const filename of files) {
64
64
* @param {string } code
65
65
*/
66
66
transform ( code ) {
67
- return code . replace ( / m o d u l e .e x p o r t s \s * = / g, 'export default ' )
68
- . replace ( / m o d u l e \. e x p o r t s \. ( \w + ) \s * = / g, ( str , name ) => {
67
+ return code . replace ( / m o d u l e \. e x p o r t s \s * = \s * { / g, 'export {' )
68
+ . replace ( / m o d u l e \. e x p o r t s \s * = / g, 'export default ' )
69
+ . replace ( / (?: m o d u l e \. ) ? e x p o r t s \. ( \w + ) \s * = / g, ( str , name ) => {
69
70
return `export const ${ name } =`
70
71
} )
71
72
}
You can’t perform that action at this time.
0 commit comments