You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
webpack is a tool which can be used to bundle application code and also to bundle library code. If you are the author of a JavaScript library and are looking to streamline your bundle strategy then this document will help you.
9
+
## 创建一个库
9
10
10
-
## Author a Library
11
-
12
-
We have here a small wrapper library to convert number 1 to 5 from number to word and vice-versa. It looks something like this.
11
+
这里有一个小的库,可以将数字1到5在其单词形式和数字形式之间转换。代码如下:
13
12
14
13
__src/index.js__
15
14
```javascript
@@ -28,54 +27,52 @@ export function wordToNum(word) {
28
27
}, -1);
29
28
};
30
29
```
31
-
32
-
The usage spec for the library will be as follows.
Now, if you run `webpack`, you will find that a largish bundle file is created. If you inspect the file, you will find that lodash has been bundled along with your code.
117
-
It would be unnecessary for your library to bundle a library like `lodash`. Hence you would want to give up control of this external library to the consumer of your library.
[Tweak your production build using webpack](/guides/production-build).
179
+
[使用 webpack 打包你的生产代码](/guides/production-build).
181
180
182
-
Add the path to your generated bundle as the package's main file in `package.json`
181
+
在 `package.json` 中指定主文件(main file)为你生成的文件的路径。
183
182
184
183
__package.json__
185
184
186
185
```javascript
187
186
{
188
187
...
189
188
"main":"dist/webpack-numbers.js",
190
-
"module":"src/index.js", //To add as standard module as per https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md#typical-usage
Now you can [publish it as an npm package](https://docs.npmjs.com/getting-started/publishing-npm-packages) and find it at [unpkg.com](https://unpkg.com/#/) to distribute it to your users.
0 commit comments