2019-06-15 02:32:33 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
console.log(require("./index"));
|
|
|
|
```
|
|
|
|
|
|
|
|
# index.ts
|
|
|
|
|
|
|
|
```typescript
|
2019-06-16 21:06:50 +08:00
|
|
|
const myName: string = "Junya";
|
|
|
|
const age: number = 22;
|
2019-06-15 02:32:33 +08:00
|
|
|
|
|
|
|
function getArray<T>(...args: T[]): T[] {
|
|
|
|
return [...args];
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(getArray("foo", "bar"));
|
|
|
|
console.log(getArray(1, 2, 3));
|
|
|
|
```
|
|
|
|
|
2019-06-19 15:39:06 +08:00
|
|
|
# webpack.config.js
|
|
|
|
|
|
|
|
```javascript
|
2019-06-20 13:58:42 +08:00
|
|
|
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
|
|
|
|
|
|
|
module.exports = (env = "development") => ({
|
|
|
|
mode: env,
|
|
|
|
entry: {
|
|
|
|
output: "./index.ts"
|
|
|
|
},
|
2019-06-19 15:39:06 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loader: "ts-loader",
|
|
|
|
options: {
|
|
|
|
transpileOnly: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: [".ts", ".js", ".json"]
|
2019-06-20 13:58:42 +08:00
|
|
|
},
|
|
|
|
plugins: [new ForkTsCheckerWebpackPlugin({ async: env === "production" })]
|
|
|
|
});
|
2019-06-19 15:39:06 +08:00
|
|
|
```
|
|
|
|
|
2019-06-15 02:32:33 +08:00
|
|
|
# dist/output.js
|
|
|
|
|
|
|
|
```javascript
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ (() => { // webpackBootstrap
|
|
|
|
/******/ var __webpack_modules__ = ([
|
|
|
|
/* 0 */,
|
2019-06-15 02:32:33 +08:00
|
|
|
/* 1 */
|
|
|
|
/*!******************!*\
|
|
|
|
!*** ./index.ts ***!
|
|
|
|
\******************/
|
2020-05-21 05:26:51 +08:00
|
|
|
/*! unknown exports (runtime-defined) */
|
2019-10-09 05:45:47 +08:00
|
|
|
/*! runtime requirements: top-level-this-exports */
|
2021-08-20 14:12:50 +08:00
|
|
|
/*! CommonJS bailout: this is used directly at 1:21-25 */
|
2019-06-16 21:06:50 +08:00
|
|
|
/***/ (function() {
|
2019-06-15 02:32:33 +08:00
|
|
|
|
2021-08-20 14:12:50 +08:00
|
|
|
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
|
|
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
|
|
to[j] = from[i];
|
|
|
|
return to;
|
2019-10-09 05:45:47 +08:00
|
|
|
};
|
2019-06-20 13:58:42 +08:00
|
|
|
var myName = "Junya";
|
|
|
|
var age = 22;
|
|
|
|
function getArray() {
|
|
|
|
var args = [];
|
|
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
|
|
args[_i] = arguments[_i];
|
|
|
|
}
|
2021-08-20 14:12:50 +08:00
|
|
|
return __spreadArray([], args);
|
2019-06-15 02:32:33 +08:00
|
|
|
}
|
|
|
|
console.log(getArray("foo", "bar"));
|
|
|
|
console.log(getArray(1, 2, 3));
|
|
|
|
|
|
|
|
|
|
|
|
/***/ })
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ ]);
|
2019-11-19 21:10:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
<details><summary><code>/* webpack runtime code */</code></summary>
|
|
|
|
|
|
|
|
``` js
|
2019-10-11 05:11:05 +08:00
|
|
|
/************************************************************************/
|
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var __webpack_module_cache__ = {};
|
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
/******/ // Check if module is in cache
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
|
|
/******/ if (cachedModule !== undefined) {
|
|
|
|
/******/ return cachedModule.exports;
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
2020-05-21 05:26:51 +08:00
|
|
|
/******/ // no module.id needed
|
|
|
|
/******/ // no module.loaded needed
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
2019-11-19 21:10:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
``` js
|
2021-08-20 14:12:50 +08:00
|
|
|
var __webpack_exports__ = {};
|
|
|
|
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
2020-05-21 05:26:51 +08:00
|
|
|
(() => {
|
2019-10-11 05:11:05 +08:00
|
|
|
/*!********************!*\
|
|
|
|
!*** ./example.js ***!
|
|
|
|
\********************/
|
2020-05-21 05:26:51 +08:00
|
|
|
/*! unknown exports (runtime-defined) */
|
2019-10-11 05:11:05 +08:00
|
|
|
/*! runtime requirements: __webpack_require__ */
|
|
|
|
console.log(__webpack_require__(/*! ./index */ 1));
|
|
|
|
|
2020-05-21 05:26:51 +08:00
|
|
|
})();
|
|
|
|
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ })()
|
|
|
|
;
|
2019-06-15 02:32:33 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
# Info
|
|
|
|
|
|
|
|
## Unoptimized
|
|
|
|
|
|
|
|
```
|
2021-08-20 14:12:50 +08:00
|
|
|
asset output.js 2.22 KiB [emitted] (name: main)
|
|
|
|
chunk (runtime: main) output.js (main) 513 bytes [entry] [rendered]
|
2020-09-21 04:39:12 +08:00
|
|
|
> ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
dependent modules 480 bytes [dependent] 1 module
|
2020-09-21 04:39:12 +08:00
|
|
|
./example.js 33 bytes [built] [code generated]
|
|
|
|
[used exports unknown]
|
|
|
|
entry ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
webpack 5.51.1 compiled successfully
|
2019-06-15 02:32:33 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Production mode
|
|
|
|
|
|
|
|
```
|
2021-08-20 14:12:50 +08:00
|
|
|
asset output.js 438 bytes [emitted] [minimized] (name: main)
|
|
|
|
chunk (runtime: main) output.js (main) 513 bytes [entry] [rendered]
|
2020-09-21 04:39:12 +08:00
|
|
|
> ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
dependent modules 480 bytes [dependent] 1 module
|
2020-09-21 04:39:12 +08:00
|
|
|
./example.js 33 bytes [built] [code generated]
|
|
|
|
[no exports used]
|
|
|
|
entry ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
webpack 5.51.1 compiled successfully
|
2019-06-15 02:32:33 +08:00
|
|
|
```
|