Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does ts-loader support HMR? #352

Closed
tobico opened this issue Nov 1, 2016 · 9 comments
Closed

Does ts-loader support HMR? #352

tobico opened this issue Nov 1, 2016 · 9 comments
Labels

Comments

@tobico
Copy link

tobico commented Nov 1, 2016

I'm trying to get hot reloading working in my TypeScript project, following this example here: https://github.com/krausest/ts-webpack-hmr

The example code README states that ts-loader does not support HMR, but there also appears to be issues here that suggest it does. I can't switch to awesome-typescript-loader right now, as it appears to be incompatible with the "pixi.js" library that I'm using.

I've tried following the example, and while I'm able to call the module.hot.accept method, webpack doesn't seem to pick it up when I change my module, and reloads the entire page.

Does ts-loader support HMR, and if so, would anyone have a working example I can refer to?

@johnnyreilly
Copy link
Member

johnnyreilly commented Nov 1, 2016

@johnnyreilly
Copy link
Member

#322

That said others seem to be using hmr successfully. Maybe @dopare could share his setup?

@d0pare
Copy link

d0pare commented Nov 1, 2016

I am using this template.
Using angular2 with dotnet core.

@kirillgroshkov
Copy link

It works for me if I set transpileOnly: true and isolatedModules: true!

@johnnyreilly
Copy link
Member

In short - yes. Use transpileOnly: true and use the fork-ts-checker-webpack-plugin for typechecking.

@johnnyreilly
Copy link
Member

I'll try and add an example at some point

@johnnyreilly
Copy link
Member

See our hot example

@rbonomo
Copy link

rbonomo commented Dec 14, 2020

See our hot example

404

@Pong420
Copy link

Pong420 commented Feb 13, 2021

https://github.com/TypeStrong/ts-loader#hot-module-replacement

create an other entry ( hot.ts ) and re-require the main entry ( main.ts ) inside the HMR callback function

require('./main');

if (module.hot) {
  module.hot.accept(['./main'], function () {
    require('./main');
  });
}

webpack.dev.js

module.exports = {
  mode: 'development',
  entry: ['./src/hot.ts'],
  // ....
}

webpack.prod.js

module.exports = {
  mode: 'production',
  entry: ['./src/main.ts'],
  // ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants