Skip to content

Commit cbc9722

Browse files
fix: compatibility with ts-loader (#183)
1 parent 071c40e commit cbc9722

8 files changed

Lines changed: 2924 additions & 1502 deletions

File tree

package-lock.json

Lines changed: 2852 additions & 1500 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"webpack": "^5.0.0"
4545
},
4646
"dependencies": {
47-
"cspell": "^6.31.1",
4847
"json-parse-better-errors": "^1.0.2",
4948
"loader-runner": "^4.1.0",
5049
"neo-async": "^2.6.2",
@@ -61,6 +60,7 @@
6160
"babel-loader": "^9.1.2",
6261
"cross-env": "^7.0.2",
6362
"css-loader": "^6.7.3",
63+
"cspell": "^6.31.1",
6464
"del": "^5.1.0",
6565
"del-cli": "^5.0.0",
6666
"eslint": "^8.39.0",
@@ -81,6 +81,7 @@
8181
"sass": "^1.62.1",
8282
"sass-loader": "^11.0.1",
8383
"standard-version": "^9.0.0",
84+
"ts-loader": "^9.2.6",
8485
"webpack": "^5.81.0"
8586
},
8687
"keywords": [

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ function pitch() {
1919
ident: l.ident,
2020
};
2121
}),
22-
_compiler: { fsStartTime: this._compiler.fsStartTime },
22+
_compiler: {
23+
fsStartTime: this._compiler.fsStartTime,
24+
options: { plugins: [] },
25+
},
2326
_compilation: {
2427
outputOptions: {
2528
hashSalt: this._compilation.outputOptions.hashSalt,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$white: #FFFFFF;

test/ts-loader-example/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const foo: string = 'foo';
2+
3+
console.log(foo);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require('path');
2+
3+
const threadLoader = require('../../src'); // eslint-disable-line import/no-extraneous-dependencies
4+
5+
module.exports = (env) => {
6+
const workerPool = {
7+
workers: +env.threads,
8+
poolTimeout: env.watch ? Infinity : 2000,
9+
};
10+
if (+env.threads > 0) {
11+
threadLoader.warmup(workerPool, ['ts-loader']);
12+
}
13+
return {
14+
mode: 'none',
15+
context: __dirname,
16+
devtool: false,
17+
entry: ['./index.ts'],
18+
output: {
19+
path: path.resolve('dist'),
20+
filename: 'bundle.js',
21+
},
22+
module: {
23+
rules: [
24+
{
25+
test: /\.ts$/,
26+
use: [
27+
env.threads !== 0 && {
28+
loader: path.resolve(__dirname, '../../dist/index.js'),
29+
options: workerPool,
30+
},
31+
{ loader: 'ts-loader', options: { happyPackMode: true } },
32+
].filter(Boolean),
33+
},
34+
],
35+
},
36+
stats: {
37+
children: false,
38+
},
39+
};
40+
};

test/webpack.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import webpack from 'webpack';
22

33
import sassLoaderConfig from './sass-loader-example/webpack.config';
4+
import tsLoaderConfig from './ts-loader-example/webpack.config';
45

56
test("Processes sass-loader's @import correctly", (done) => {
67
const config = sassLoaderConfig({});
@@ -21,3 +22,23 @@ test("Processes sass-loader's @import correctly", (done) => {
2122
done();
2223
});
2324
}, 30000);
25+
26+
test('Processes ts-loader correctly', (done) => {
27+
const config = tsLoaderConfig({});
28+
29+
webpack(config, (err, stats) => {
30+
if (err) {
31+
// eslint-disable-next-line no-console
32+
console.error(err);
33+
}
34+
35+
expect(err).toBe(null);
36+
37+
if (stats.hasErrors()) {
38+
// eslint-disable-next-line no-console
39+
console.error(stats.toJson().errors);
40+
}
41+
expect(stats.hasErrors()).toBe(false);
42+
done();
43+
});
44+
}, 30000);

0 commit comments

Comments
 (0)