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

Commit 128c474

Browse files
author
vakrilov
committed
feat: no need of "page" suffix for HMR to work
1 parent ebc7029 commit 128c474

File tree

9 files changed

+38
-74
lines changed

9 files changed

+38
-74
lines changed

bundle-config-loader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import unitTestingConfigLoader from "./unit-testing-config-loader";
22
import { loader } from "webpack";
33
import { getOptions } from "loader-utils";
44

5+
// Matches all source, markup and style files that are not in App_Resources
6+
const defaultMatch = /(?<!App_Resources.*)\.(xml|css|js|ts|scss)$/;
7+
58
const loader: loader.Loader = function (source, map) {
69
const {
710
angular = false,
811
loadCss = true,
912
unitTesting,
1013
projectRoot,
1114
appFullPath,
12-
registerModules = /(root|page)(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.(xml|css|js|ts|scss)$/
13-
} = getOptions(this);;
15+
registerModules = defaultMatch,
16+
} = getOptions(this);
1417

1518
if (unitTesting) {
1619
source = unitTestingConfigLoader({ appFullPath, projectRoot, angular, rootPagesRegExp: registerModules });

demo/AngularApp/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = env => {
3333

3434
// Default destination inside platforms/<platform>/...
3535
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
36-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3736

3837
const {
3938
// The 'appPath' and 'appResourcesPath' values are fetched from

demo/JavaScriptApp/webpack.config.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = env => {
2828

2929
// Default destination inside platforms/<platform>/...
3030
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
31-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3231

3332
const {
3433
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -103,7 +102,7 @@ module.exports = env => {
103102
'~': appFullPath
104103
},
105104
// don't resolve symlinks to symlinked modules
106-
symlinks: false
105+
symlinks: true
107106
},
108107
resolveLoader: {
109108
// don't resolve symlinks to symlinked loaders
@@ -180,18 +179,8 @@ module.exports = env => {
180179
},
181180

182181
{
183-
test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/,
184-
use: "nativescript-dev-webpack/script-hot-loader"
185-
},
186-
187-
{
188-
test: /\.(css|scss)$/,
189-
use: "nativescript-dev-webpack/style-hot-loader"
190-
},
191-
192-
{
193-
test: /\.(html|xml)$/,
194-
use: "nativescript-dev-webpack/markup-hot-loader"
182+
test: /\.(js|css|scss|html|xml)$/,
183+
use: "nativescript-dev-webpack/hmr/hot-loader"
195184
},
196185

197186
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },
@@ -234,7 +223,7 @@ module.exports = env => {
234223
platforms,
235224
}),
236225
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
237-
new nsWebpack.WatchStateLoggerPlugin(),
226+
new nsWebpack.WatchStateLoggerPlugin()
238227
],
239228
};
240229

demo/TypeScriptApp/webpack.config.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module.exports = env => {
2929

3030
// Default destination inside platforms/<platform>/...
3131
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
32-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3332

3433
const {
3534
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -186,18 +185,8 @@ module.exports = env => {
186185
},
187186

188187
{
189-
test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/,
190-
use: "nativescript-dev-webpack/script-hot-loader"
191-
},
192-
193-
{
194-
test: /\.(css|scss)$/,
195-
use: "nativescript-dev-webpack/style-hot-loader"
196-
},
197-
198-
{
199-
test: /\.(html|xml)$/,
200-
use: "nativescript-dev-webpack/markup-hot-loader"
188+
test: /\.(ts|css|scss|html|xml)$/,
189+
use: "nativescript-dev-webpack/hmr/hot-loader"
201190
},
202191

203192
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },
@@ -265,7 +254,7 @@ module.exports = env => {
265254
async: false,
266255
useTypescriptIncrementalApi: true,
267256
memoryLimit: 4096
268-
}),
257+
})
269258
],
270259
};
271260

hmr/hot-loader.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { loader } from "webpack";
22
import { convertToUnixPath } from "../lib/utils";
33
import { extname } from "path";
4+
import { getOptions } from "loader-utils";
45

56
const extMap = {
6-
".css" : "style",
7-
".scss" : "style",
8-
".less" : "style",
9-
".js" : "script",
10-
".ts" : "script",
11-
".xml" : "markup",
12-
".html" : "markup",
7+
".css": "style",
8+
".scss": "style",
9+
".less": "style",
10+
".js": "script",
11+
".ts": "script",
12+
".xml": "markup",
13+
".html": "markup",
1314
}
1415

1516
const loader: loader.Loader = function (source, map) {
@@ -18,16 +19,23 @@ const loader: loader.Loader = function (source, map) {
1819
const ext = extname(modulePath).toLowerCase();
1920
const typeStyle = extMap[ext] || "unknown";
2021

22+
const options = getOptions(this) || {};
23+
const alwaysSelfAccept = options.alwaysSelfAccept;
24+
const trace = options.trace;
25+
26+
const shouldAutoAcceptCheck = `&& global._isModuleLoadedForUI && global._isModuleLoadedForUI("${modulePath}")`;
27+
const traceCode = `console.log("[hot-loader]: Self-accept module: ${modulePath}");`;
28+
2129
const hotCode = `
22-
if (module.hot && global._shouldAutoAcceptModule && global._shouldAutoAcceptModule(module.id)) {
23-
console.log("AUTO ACCEPT MODULE: ", module.id, '${modulePath}')
30+
if (module.hot ${alwaysSelfAccept ? "" : shouldAutoAcceptCheck} ) {
31+
${trace ? traceCode : ""}
2432
module.hot.accept();
2533
module.hot.dispose(() => {
26-
global.hmrRefresh({ type: '${typeStyle}', path: '${modulePath}' });
27-
})
34+
global.hmrRefresh({ type: "${typeStyle}", path: "${modulePath}" });
35+
});
2836
}`;
2937

30-
this.callback(null, `${source};${hotCode}`, map);
38+
this.callback(null, `${source}; ${hotCode} `, map);
3139
};
3240

3341
export default loader;

templates/webpack.angular.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ module.exports = env => {
3232

3333
// Default destination inside platforms/<platform>/...
3434
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
35-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3635

3736
const {
3837
// The 'appPath' and 'appResourcesPath' values are fetched from

templates/webpack.javascript.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = env => {
2727

2828
// Default destination inside platforms/<platform>/...
2929
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
30-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3130

3231
const {
3332
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -179,18 +178,8 @@ module.exports = env => {
179178
},
180179

181180
{
182-
test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/,
183-
use: "nativescript-dev-webpack/script-hot-loader"
184-
},
185-
186-
{
187-
test: /\.(css|scss)$/,
188-
use: "nativescript-dev-webpack/style-hot-loader"
189-
},
190-
191-
{
192-
test: /\.(html|xml)$/,
193-
use: "nativescript-dev-webpack/markup-hot-loader"
181+
test: /\.(js|css|scss|html|xml)$/,
182+
use: "nativescript-dev-webpack/hmr/hot-loader"
194183
},
195184

196185
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },

templates/webpack.typescript.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = env => {
2828

2929
// Default destination inside platforms/<platform>/...
3030
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
31-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3231

3332
const {
3433
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -183,20 +182,10 @@ module.exports = env => {
183182
},
184183
].filter(loader => !!loader)
185184
},
186-
187-
{
188-
test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/,
189-
use: "nativescript-dev-webpack/script-hot-loader"
190-
},
191-
192-
{
193-
test: /\.(css|scss)$/,
194-
use: "nativescript-dev-webpack/style-hot-loader"
195-
},
196-
185+
197186
{
198-
test: /\.(html|xml)$/,
199-
use: "nativescript-dev-webpack/markup-hot-loader"
187+
test: /\.(ts|css|scss|html|xml)$/,
188+
use: "nativescript-dev-webpack/hmr/hot-loader"
200189
},
201190

202191
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },

templates/webpack.vue.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module.exports = env => {
3131

3232
// Default destination inside platforms/<platform>/...
3333
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
34-
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
3534

3635
const {
3736
// The 'appPath' and 'appResourcesPath' values are fetched from
@@ -265,7 +264,7 @@ module.exports = env => {
265264
if (unitTesting) {
266265
config.module.rules.push(
267266
{
268-
test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/,
267+
test: /-page\.js$/,
269268
use: "nativescript-dev-webpack/script-hot-loader"
270269
},
271270
{

0 commit comments

Comments
 (0)