fix(webpack5): include hmr handling only when enabled (#9685)

* fix(webpack): respect hmr flag

* fix(webpack): ensure correct loader order is used

* chore: cleanup

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
This commit is contained in:
Eduardo Speroni
2021-11-29 13:55:10 -03:00
committed by GitHub
parent 57eac49128
commit 05082b1aec
10 changed files with 190 additions and 344 deletions

View File

@ -198,12 +198,24 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.options({
platform,
})
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
injectHMRRuntime: true,
});
.end();
config.when(env.hmr, (config) => {
config.module
.rule('bundle')
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
injectHMRRuntime: true,
});
});
// worker-loader should be declared before ts-loader
config.module
.rule('workers')
.test(/\.(js|ts)$/)
.use('nativescript-worker-loader')
.loader('nativescript-worker-loader');
// set up ts support
config.module
@ -249,12 +261,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.exclude.add(/node_modules/)
.end();
config.module
.rule('workers')
.test(/\.(js|ts)$/)
.use('nativescript-worker-loader')
.loader('nativescript-worker-loader');
// config.resolve.extensions.add('.xml');
// set up xml
config.module

View File

@ -34,18 +34,21 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
virtualEntryPath
);
// set up core HMR
config.module
.rule('hmr-core')
.test(/\.js$/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath(),
});
config.when(env.hmr, (config) => {
// set up core HMR
config.module
.rule('hmr-core')
.before('js')
.test(/\.js$/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath(),
});
});
return config;
}

View File

@ -34,18 +34,21 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
virtualEntryPath
);
// set up core HMR
config.module
.rule('hmr-core')
.test(/\.(js|ts)$/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath(),
});
config.when(env.hmr, (config) => {
// set up core HMR
config.module
.rule('hmr-core')
.before('ts')
.test(/\.(js|ts)$/)
.exclude.add(/node_modules/)
.add(entryPath)
.end()
.use('nativescript-hot-loader')
.loader('nativescript-hot-loader')
.options({
appPath: getEntryDirPath(),
});
});
return config;
}