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

fix(hmr): run ts-loader in transpileOnly mode #878

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"clean-webpack-plugin": "~1.0.0",
"copy-webpack-plugin": "~4.6.0",
"css-loader": "~2.1.1",
"fork-ts-checker-webpack-plugin": "^1.2.0",
"global-modules-path": "2.0.0",
"minimatch": "3.0.4",
"nativescript-hook": "0.2.4",
Expand Down
13 changes: 12 additions & 1 deletion templates/webpack.typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
const TerserPlugin = require("terser-webpack-plugin");
Expand Down Expand Up @@ -54,6 +55,9 @@ module.exports = env => {
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
const entryPath = `.${sep}${entryModule}.ts`;
const entries = { bundle: entryPath };

const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json");

if (platform === "ios") {
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
};
Expand Down Expand Up @@ -206,7 +210,8 @@ module.exports = env => {
use: {
loader: "ts-loader",
options: {
configFile: "tsconfig.tns.json",
configFile: tsConfigPath,
transpileOnly: !!hmr,
allowTsInNodeModules: true,
compilerOptions: {
sourceMap: isAnySourceMapEnabled
Expand Down Expand Up @@ -289,6 +294,12 @@ module.exports = env => {

if (hmr) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());

// With HMR ts-loader should run in `transpileOnly` mode,
// so assure type-checking with fork-ts-checker-webpack-plugin
config.plugins.push(new ForkTsCheckerWebpackPlugin({
tsconfig: tsConfigPath
}));
}


Expand Down