@ecoding/base.build 0.2.3 → 0.2.5
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/bin/index.js +11 -0
- package/libs/output/readme.md +68 -37
- package/package.json +6 -2
package/bin/index.js
ADDED
package/libs/output/readme.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# output
|
|
2
2
|
|
|
3
3
|
## path
|
|
4
|
+
|
|
4
5
|
> 输出文件目录(将来所有资源输出的公共目录)
|
|
5
6
|
|
|
6
7
|
## publicPath
|
|
8
|
+
|
|
7
9
|
> 所有资源引入公共路径前缀 --> 'imgs/a.jpg' --> '/imgs/a.jpg'
|
|
10
|
+
|
|
8
11
|
```javascript
|
|
9
12
|
// 可在业务代码中 动态修改 output 内的publicPath
|
|
10
13
|
if(...) {
|
|
@@ -13,39 +16,53 @@ if(...) {
|
|
|
13
16
|
```
|
|
14
17
|
|
|
15
18
|
## filename
|
|
19
|
+
|
|
16
20
|
> 入口代码块文件名称(指定名称+目录)
|
|
17
21
|
|
|
18
22
|
## chunkFilename
|
|
23
|
+
|
|
19
24
|
> 代码块文件名称
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
|
|
26
|
+
- 1. 每一个入口会生成一个 chunk
|
|
27
|
+
- 2. 代码分割动态 import 引入代码会生成一个 chunk
|
|
22
28
|
|
|
23
29
|
## library
|
|
24
|
-
> 整个库向外暴露的变量名,library: '[name]'
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
> 整个库向外暴露的变量名,library: '[name]', 它被用来指定模块的名字,就像 jQuery,它的模块名叫 jquery
|
|
32
|
+
|
|
33
|
+
## globalObject
|
|
34
|
+
|
|
35
|
+
> 全局上下文变量,默认是 window
|
|
28
36
|
|
|
29
37
|
## umdNamedDefine
|
|
30
|
-
> 如果在output.libraryTarget被设置成umd形式,并且output.library也被设置时,将该选项设为true将会给命名给amd模块
|
|
31
38
|
|
|
39
|
+
> 如果在 output.libraryTarget 被设置成 umd 形式,并且 output.library 也被设置时,将该选项设为 true 将会给命名给 amd 模块
|
|
40
|
+
|
|
41
|
+
## libraryTarget
|
|
32
42
|
|
|
43
|
+
> 导出库的规范方式,指定打包后的脚本如何导出模块,具体如下
|
|
33
44
|
|
|
34
45
|
#### var - 默认值
|
|
46
|
+
|
|
35
47
|
> 当库被加载时,那么库的返回值会被分配到使用用 var 声明的变量上。
|
|
48
|
+
|
|
36
49
|
```javascript
|
|
37
50
|
var myDemo = _entry_return_;
|
|
38
51
|
myDemo();
|
|
39
52
|
```
|
|
40
53
|
|
|
41
54
|
#### assign
|
|
42
|
-
|
|
55
|
+
|
|
56
|
+
> 会把库返回值分配给一个没使用 var 声明的变量中,如果这个变量没有在引入作用域中提前声明过,那么将会挂载在全局作用域中。(注意,这个行为有可能会覆盖全局作用域中的已有变量)
|
|
57
|
+
|
|
43
58
|
```javascript
|
|
44
59
|
myDemo = _entry_return_;
|
|
45
60
|
```
|
|
46
61
|
|
|
47
62
|
#### this
|
|
48
|
-
|
|
63
|
+
|
|
64
|
+
> 将库的返回值分配给 this 对象的由 output.library 指定的属性。其中 this 的意义由用户决定。
|
|
65
|
+
|
|
49
66
|
```javascript
|
|
50
67
|
this["myDemo"] = _entry_return_;
|
|
51
68
|
this.myDemo();
|
|
@@ -53,28 +70,36 @@ myDemo(); // if this is window
|
|
|
53
70
|
```
|
|
54
71
|
|
|
55
72
|
#### window
|
|
56
|
-
|
|
73
|
+
|
|
74
|
+
> 将库的返回值分配给 browser window 对象的由 output.library 指定的属性。
|
|
75
|
+
|
|
57
76
|
```javascript
|
|
58
77
|
window["myDemo"] = _entry_return_;
|
|
59
78
|
window.myDemo.doSomething();
|
|
60
79
|
```
|
|
61
80
|
|
|
62
81
|
#### global
|
|
63
|
-
|
|
82
|
+
|
|
83
|
+
> 将库的返回值分配给 node global 对象的由 output.library 指定的属性。
|
|
84
|
+
|
|
64
85
|
```javascript
|
|
65
86
|
global["myDemo"] = _entry_return_;
|
|
66
87
|
global.myDemo();
|
|
67
88
|
```
|
|
68
89
|
|
|
69
90
|
#### commonjs
|
|
70
|
-
|
|
91
|
+
|
|
92
|
+
> 将库的返回值分配给 exports 对象的由 output.library 指定的属性。正如名字所指,这个选项可以使用在 CommonJS 环境。
|
|
93
|
+
|
|
71
94
|
```javascript
|
|
72
95
|
exports["myDemo"] = _entry_return_;
|
|
73
96
|
require("myDemo").doSomething();
|
|
74
97
|
```
|
|
75
98
|
|
|
76
99
|
#### commonjs2
|
|
77
|
-
|
|
100
|
+
|
|
101
|
+
> 将库的返回值分配给 module.exports。正如名字所指,这个选项可以使用在 CommonJS 环境。
|
|
102
|
+
|
|
78
103
|
```javascript
|
|
79
104
|
module.exports = _entry_return_;
|
|
80
105
|
const myDemo = require("myDemo");
|
|
@@ -82,48 +107,52 @@ myDemo();
|
|
|
82
107
|
```
|
|
83
108
|
|
|
84
109
|
#### amd
|
|
85
|
-
|
|
110
|
+
|
|
111
|
+
> 这个选项会把库作为 AMD 模块导出。AMD 模块要求输入脚本(例如由 script 标签加载的第一个脚本)被定义为具有特定属性,例如通常由 RequireJS 或任何兼容的加载器(诸如 almond)提供的 require 和 define 属性。否则,直接加载生成的 AMD 捆绑包将导致类似 define is not defined 的错误。
|
|
112
|
+
|
|
86
113
|
```javascript
|
|
87
|
-
define("myDemo", [], function() {
|
|
88
|
-
|
|
114
|
+
define("myDemo", [], function () {
|
|
115
|
+
return _entry_return_;
|
|
89
116
|
});
|
|
90
117
|
```
|
|
91
|
-
|
|
118
|
+
|
|
119
|
+
以上的代码可以作为 script 标签引入代码的一部分被包含
|
|
92
120
|
|
|
93
121
|
然后在通过以下代码调用
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
require(["myDemo"], function (myDemo) {
|
|
125
|
+
myDemo();
|
|
97
126
|
});
|
|
98
127
|
```
|
|
99
128
|
|
|
100
129
|
**注意**
|
|
101
130
|
|
|
102
|
-
|
|
103
|
-
``` javascript
|
|
104
|
-
define([], function() {
|
|
105
|
-
return _entry_return_;
|
|
106
|
-
});
|
|
107
|
-
```
|
|
131
|
+
如果 output.library 没有定义有效值,那么生成的代码将如下:
|
|
108
132
|
|
|
133
|
+
```javascript
|
|
134
|
+
define([], function () {
|
|
135
|
+
return _entry_return_;
|
|
136
|
+
});
|
|
137
|
+
```
|
|
109
138
|
|
|
110
139
|
#### umd
|
|
111
|
-
|
|
140
|
+
|
|
141
|
+
> 这个选项会尝试把库暴露给前使用的模块定义系统,这使其和 CommonJS、AMD 兼容或者暴露为全局变量。**注意** output.library 选项在这里是必须的。
|
|
142
|
+
|
|
112
143
|
```javascript
|
|
113
144
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
else
|
|
121
|
-
root["MyLibrary"] = factory();
|
|
122
|
-
})(typeof self !== 'undefined' ? self : this, function() {
|
|
123
|
-
return _entry_return_;
|
|
145
|
+
if (typeof exports === "object" && typeof module === "object") module.exports = factory();
|
|
146
|
+
else if (typeof define === "function" && define.amd) define([], factory);
|
|
147
|
+
else if (typeof exports === "object") exports["MyLibrary"] = factory();
|
|
148
|
+
else root["MyLibrary"] = factory();
|
|
149
|
+
})(typeof self !== "undefined" ? self : this, function () {
|
|
150
|
+
return _entry_return_;
|
|
124
151
|
});
|
|
125
152
|
```
|
|
153
|
+
|
|
126
154
|
**配置案例**
|
|
155
|
+
|
|
127
156
|
```javascript
|
|
128
157
|
output: {
|
|
129
158
|
library: {
|
|
@@ -136,7 +165,9 @@ output: {
|
|
|
136
165
|
```
|
|
137
166
|
|
|
138
167
|
#### jsonp
|
|
168
|
+
|
|
139
169
|
> 这个方法会使用 jsonp 的方式把结果包裹起来。
|
|
170
|
+
|
|
140
171
|
```javascript
|
|
141
172
|
myDemo(_entry_return_);
|
|
142
|
-
```
|
|
173
|
+
```
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/base.build",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "tpl building",
|
|
5
5
|
"author": "cxc",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ebuild": "bin/index.js"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
11
|
+
"bin",
|
|
8
12
|
"libs"
|
|
9
13
|
],
|
|
10
14
|
"dependencies": {
|
|
@@ -51,5 +55,5 @@
|
|
|
51
55
|
"publishConfig": {
|
|
52
56
|
"access": "public"
|
|
53
57
|
},
|
|
54
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "b070ec6b9167777a75c19170d6a929982cbc82e7"
|
|
55
59
|
}
|