Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 0317729

Browse files
author
Alexander Vakrilov
authored
fix(hmr): run ts-loader in transpileOnly mode (#878)
1 parent 269308b commit 0317729

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"clean-webpack-plugin": "~1.0.0",
7979
"copy-webpack-plugin": "~4.6.0",
8080
"css-loader": "~2.1.1",
81+
"fork-ts-checker-webpack-plugin": "^1.2.0",
8182
"global-modules-path": "2.0.0",
8283
"minimatch": "3.0.4",
8384
"nativescript-hook": "0.2.4",

Diff for: templates/webpack.typescript.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
8+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
89
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
910
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1011
const TerserPlugin = require("terser-webpack-plugin");
@@ -54,6 +55,9 @@ module.exports = env => {
5455
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
5556
const entryPath = `.${sep}${entryModule}.ts`;
5657
const entries = { bundle: entryPath };
58+
59+
const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json");
60+
5761
if (platform === "ios") {
5862
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
5963
};
@@ -206,7 +210,8 @@ module.exports = env => {
206210
use: {
207211
loader: "ts-loader",
208212
options: {
209-
configFile: "tsconfig.tns.json",
213+
configFile: tsConfigPath,
214+
transpileOnly: !!hmr,
210215
allowTsInNodeModules: true,
211216
compilerOptions: {
212217
sourceMap: isAnySourceMapEnabled
@@ -289,6 +294,12 @@ module.exports = env => {
289294

290295
if (hmr) {
291296
config.plugins.push(new webpack.HotModuleReplacementPlugin());
297+
298+
// With HMR ts-loader should run in `transpileOnly` mode,
299+
// so assure type-checking with fork-ts-checker-webpack-plugin
300+
config.plugins.push(new ForkTsCheckerWebpackPlugin({
301+
tsconfig: tsConfigPath
302+
}));
292303
}
293304

294305

0 commit comments

Comments
 (0)