Skip to content

Commit 3639cbd

Browse files
authored
Backport #1317 to v8 (#1319)
* Backport "Fixed impossibility to have several instances of ts-loader with different compiler options" #1317 to v8 * regen comparison tests
1 parent 6787a39 commit 3639cbd

File tree

14 files changed

+326
-3
lines changed

14 files changed

+326
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v8.3.0
4+
5+
* [Fixed impossibility to have several instances of ts-loader with different compiler options](https://github.com/TypeStrong/ts-loader/issues/1316) - thanks @timocov
6+
* This is a backport from v9.2.0 for webpack 4 compatibility
7+
38
## v8.2.0
49

510
* [Use caches for module resolution and type reference directives when using compiler default functions](https://github.com/TypeStrong/ts-loader/pull/1287) - thanks @sheetalkamat - uses: https://github.com/microsoft/TypeScript/pull/43700

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.2.0",
3+
"version": "8.3.0",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ function getOptionsHash(loaderOptions: LoaderOptions) {
161161
const hash = crypto.createHash('sha256');
162162
Object.keys(loaderOptions).forEach(key => {
163163
const value = loaderOptions[key];
164-
if (value) {
165-
hash.update(key + value.toString());
164+
if (value !== undefined) {
165+
const valueString =
166+
typeof value === 'function' ? value.toString() : JSON.stringify(value);
167+
hash.update(key + valueString);
166168
}
167169
});
168170
return hash.digest('hex').substring(0, 16);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './submodule-es5';
2+
import './submodule-es6';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
/******/
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
/******/
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId]) {
10+
/******/ return installedModules[moduleId].exports;
11+
/******/ }
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ i: moduleId,
15+
/******/ l: false,
16+
/******/ exports: {}
17+
/******/ };
18+
/******/
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
/******/
22+
/******/ // Flag the module as loaded
23+
/******/ module.l = true;
24+
/******/
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
/******/
29+
/******/
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
/******/
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
/******/
36+
/******/ // define getter function for harmony exports
37+
/******/ __webpack_require__.d = function(exports, name, getter) {
38+
/******/ if(!__webpack_require__.o(exports, name)) {
39+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40+
/******/ }
41+
/******/ };
42+
/******/
43+
/******/ // define __esModule on exports
44+
/******/ __webpack_require__.r = function(exports) {
45+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47+
/******/ }
48+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
49+
/******/ };
50+
/******/
51+
/******/ // create a fake namespace object
52+
/******/ // mode & 1: value is a module id, require it
53+
/******/ // mode & 2: merge all properties of value into the ns
54+
/******/ // mode & 4: return value when already ns object
55+
/******/ // mode & 8|1: behave like require
56+
/******/ __webpack_require__.t = function(value, mode) {
57+
/******/ if(mode & 1) value = __webpack_require__(value);
58+
/******/ if(mode & 8) return value;
59+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60+
/******/ var ns = Object.create(null);
61+
/******/ __webpack_require__.r(ns);
62+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64+
/******/ return ns;
65+
/******/ };
66+
/******/
67+
/******/ // getDefaultExport function for compatibility with non-harmony modules
68+
/******/ __webpack_require__.n = function(module) {
69+
/******/ var getter = module && module.__esModule ?
70+
/******/ function getDefault() { return module['default']; } :
71+
/******/ function getModuleExports() { return module; };
72+
/******/ __webpack_require__.d(getter, 'a', getter);
73+
/******/ return getter;
74+
/******/ };
75+
/******/
76+
/******/ // Object.prototype.hasOwnProperty.call
77+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78+
/******/
79+
/******/ // __webpack_public_path__
80+
/******/ __webpack_require__.p = "";
81+
/******/
82+
/******/
83+
/******/ // Load entry module and return exports
84+
/******/ return __webpack_require__(__webpack_require__.s = "./app.ts");
85+
/******/ })
86+
/************************************************************************/
87+
/******/ ({
88+
89+
/***/ "./app.ts":
90+
/*!****************!*\
91+
!*** ./app.ts ***!
92+
\****************/
93+
/*! no exports provided */
94+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
95+
96+
"use strict";
97+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./submodule-es5 */ \"./submodule-es5/index.ts\");\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_submodule_es5__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./submodule-es6 */ \"./submodule-es6/index.ts\");\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_submodule_es6__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\n\n//# sourceURL=webpack:///./app.ts?");
98+
99+
/***/ }),
100+
101+
/***/ "./submodule-es5/index.ts":
102+
/*!********************************!*\
103+
!*** ./submodule-es5/index.ts ***!
104+
\********************************/
105+
/*! no static exports found */
106+
/***/ (function(module, exports) {
107+
108+
eval("var string = 'Hello from es5 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es5/index.ts?");
109+
110+
/***/ }),
111+
112+
/***/ "./submodule-es6/index.ts":
113+
/*!********************************!*\
114+
!*** ./submodule-es6/index.ts ***!
115+
\********************************/
116+
/*! no static exports found */
117+
/***/ (function(module, exports) {
118+
119+
eval("const set = new Set([42]);\r\nfor (const value of set) {\r\n console.log(value);\r\n}\r\nconst string = 'Hello from es6 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es6/index.ts?");
120+
121+
/***/ })
122+
123+
/******/ });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Asset Size Chunks Chunk Names
2+
bundle.js 5.21 KiB main [emitted] main
3+
Entrypoint main = bundle.js
4+
[./app.ts] 52 bytes {main} [built]
5+
[./submodule-es5/index.ts] 59 bytes {main} [built]
6+
[./submodule-es6/index.ts] 145 bytes {main} [built]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
/******/
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
/******/
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId]) {
10+
/******/ return installedModules[moduleId].exports;
11+
/******/ }
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ i: moduleId,
15+
/******/ l: false,
16+
/******/ exports: {}
17+
/******/ };
18+
/******/
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
/******/
22+
/******/ // Flag the module as loaded
23+
/******/ module.l = true;
24+
/******/
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
/******/
29+
/******/
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
/******/
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
/******/
36+
/******/ // define getter function for harmony exports
37+
/******/ __webpack_require__.d = function(exports, name, getter) {
38+
/******/ if(!__webpack_require__.o(exports, name)) {
39+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40+
/******/ }
41+
/******/ };
42+
/******/
43+
/******/ // define __esModule on exports
44+
/******/ __webpack_require__.r = function(exports) {
45+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47+
/******/ }
48+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
49+
/******/ };
50+
/******/
51+
/******/ // create a fake namespace object
52+
/******/ // mode & 1: value is a module id, require it
53+
/******/ // mode & 2: merge all properties of value into the ns
54+
/******/ // mode & 4: return value when already ns object
55+
/******/ // mode & 8|1: behave like require
56+
/******/ __webpack_require__.t = function(value, mode) {
57+
/******/ if(mode & 1) value = __webpack_require__(value);
58+
/******/ if(mode & 8) return value;
59+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60+
/******/ var ns = Object.create(null);
61+
/******/ __webpack_require__.r(ns);
62+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64+
/******/ return ns;
65+
/******/ };
66+
/******/
67+
/******/ // getDefaultExport function for compatibility with non-harmony modules
68+
/******/ __webpack_require__.n = function(module) {
69+
/******/ var getter = module && module.__esModule ?
70+
/******/ function getDefault() { return module['default']; } :
71+
/******/ function getModuleExports() { return module; };
72+
/******/ __webpack_require__.d(getter, 'a', getter);
73+
/******/ return getter;
74+
/******/ };
75+
/******/
76+
/******/ // Object.prototype.hasOwnProperty.call
77+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78+
/******/
79+
/******/ // __webpack_public_path__
80+
/******/ __webpack_require__.p = "";
81+
/******/
82+
/******/
83+
/******/ // Load entry module and return exports
84+
/******/ return __webpack_require__(__webpack_require__.s = "./app.ts");
85+
/******/ })
86+
/************************************************************************/
87+
/******/ ({
88+
89+
/***/ "./app.ts":
90+
/*!****************!*\
91+
!*** ./app.ts ***!
92+
\****************/
93+
/*! no exports provided */
94+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
95+
96+
"use strict";
97+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./submodule-es5 */ \"./submodule-es5/index.ts\");\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_submodule_es5__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./submodule-es6 */ \"./submodule-es6/index.ts\");\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_submodule_es6__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\n\n//# sourceURL=webpack:///./app.ts?");
98+
99+
/***/ }),
100+
101+
/***/ "./submodule-es5/index.ts":
102+
/*!********************************!*\
103+
!*** ./submodule-es5/index.ts ***!
104+
\********************************/
105+
/*! no static exports found */
106+
/***/ (function(module, exports) {
107+
108+
eval("var string = 'Hello from es5 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es5/index.ts?");
109+
110+
/***/ }),
111+
112+
/***/ "./submodule-es6/index.ts":
113+
/*!********************************!*\
114+
!*** ./submodule-es6/index.ts ***!
115+
\********************************/
116+
/*! no static exports found */
117+
/***/ (function(module, exports) {
118+
119+
eval("const set = new Set([42]);\r\nfor (const value of set) {\r\n console.log(value);\r\n}\r\nconst string = 'Hello from es6 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es6/index.ts?");
120+
121+
/***/ })
122+
123+
/******/ });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Asset Size Chunks Chunk Names
2+
bundle.js 5.21 KiB main [emitted] main
3+
Entrypoint main = bundle.js
4+
[./app.ts] 52 bytes {main} [built]
5+
[./submodule-es5/index.ts] 59 bytes {main} [built]
6+
[./submodule-es6/index.ts] 145 bytes {main} [built]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const string = 'Hello from es5 file';
2+
console.log(string);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const set = new Set([42]);
2+
for (const value of set) {
3+
console.log(value);
4+
}
5+
6+
const string = 'Hello from es6 file';
7+
console.log(string);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
mode: 'development',
3+
entry: './app.ts',
4+
output: {
5+
filename: 'bundle.js'
6+
},
7+
resolve: {
8+
extensions: ['.ts']
9+
},
10+
module: {
11+
rules: [
12+
{
13+
test: /submodule-es6.*\.ts$/,
14+
loader: 'ts-loader',
15+
options: {
16+
compilerOptions: {
17+
target: 'es6',
18+
},
19+
},
20+
},
21+
{
22+
test: /submodule-es5.*\.ts$/,
23+
loader: 'ts-loader',
24+
options: {
25+
compilerOptions: {
26+
target: 'es5',
27+
},
28+
},
29+
}
30+
]
31+
}
32+
}

0 commit comments

Comments
 (0)