From 6b5aa365be88709dd086189921a87faf8bf7cfde Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 25 Jun 2019 09:25:36 +0300 Subject: [PATCH 01/10] feat: support for file qualifiers --- bundle-config-loader.js | 9 ++++++++- demo/JavaScriptApp/webpack.config.js | 2 +- demo/TypeScriptApp/webpack.config.js | 2 +- templates/webpack.javascript.js | 2 +- templates/webpack.typescript.js | 2 +- templates/webpack.vue.js | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bundle-config-loader.js b/bundle-config-loader.js index 4daa915b..bd7d7d22 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.js @@ -2,7 +2,14 @@ const unitTestingConfigLoader = require("./unit-testing-config-loader"); module.exports = function (source, map) { this.cacheable(); - const { angular = false, loadCss = true, unitTesting, projectRoot, appFullPath, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query; + const { + angular = false, + loadCss = true, + unitTesting, + projectRoot, + appFullPath, + registerModules = /(root|page)(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.(xml|css|js|ts|scss)$/ + } = this.query; if (unitTesting) { source = unitTestingConfigLoader({ appFullPath, projectRoot, angular, rootPagesRegExp: registerModules }); diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index e285ce31..b6c0e6d1 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -180,7 +180,7 @@ module.exports = env => { }, { - test: /-page\.js$/, + test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, use: "nativescript-dev-webpack/script-hot-loader" }, diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 74dfb0dd..2ae69690 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -186,7 +186,7 @@ module.exports = env => { }, { - test: /-page\.ts$/, + test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/, use: "nativescript-dev-webpack/script-hot-loader" }, diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index b976e827..a756fbcf 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -179,7 +179,7 @@ module.exports = env => { }, { - test: /-page\.js$/, + test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, use: "nativescript-dev-webpack/script-hot-loader" }, diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index b04e72e2..2f60c565 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -185,7 +185,7 @@ module.exports = env => { }, { - test: /-page\.ts$/, + test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/, use: "nativescript-dev-webpack/script-hot-loader" }, diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 600c399c..52a98979 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -265,7 +265,7 @@ module.exports = env => { if (unitTesting) { config.module.rules.push( { - test: /-page\.js$/, + test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, use: "nativescript-dev-webpack/script-hot-loader" }, { From fd48b8a4fde577d376eb411f16c3e3de9fa7df99 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Mon, 1 Jul 2019 14:37:19 +0300 Subject: [PATCH 02/10] refactor: convert bundle-config-loader to TS --- .gitignore | 4 ++++ bundle-config-loader.js => bundle-config-loader.ts | 14 +++++++++----- jasmine-config/jasmine.json | 3 ++- package.json | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) rename bundle-config-loader.js => bundle-config-loader.ts (86%) diff --git a/.gitignore b/.gitignore index cee7d177..0d149819 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,10 @@ jasmine-config/reporter.d.ts jasmine-config/reporter.js jasmine-config/reporter.js.map +bundle-config-loader.d.ts +bundle-config-loader.js +bundle-config-loader.js.map + **/*.spec.js* **/*.spec.d.ts* diff --git a/bundle-config-loader.js b/bundle-config-loader.ts similarity index 86% rename from bundle-config-loader.js rename to bundle-config-loader.ts index bd7d7d22..8de5d694 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.ts @@ -1,15 +1,16 @@ -const unitTestingConfigLoader = require("./unit-testing-config-loader"); +import unitTestingConfigLoader from "./unit-testing-config-loader"; +import { loader } from "webpack"; +import { getOptions } from "loader-utils"; -module.exports = function (source, map) { - this.cacheable(); +const loader: loader.Loader = function (source, map) { const { angular = false, loadCss = true, unitTesting, projectRoot, appFullPath, - registerModules = /(root|page)(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.(xml|css|js|ts|scss)$/ - } = this.query; + registerModules = /(root|page)(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.(xml|css|js|ts|scss)$/ + } = getOptions(this);; if (unitTesting) { source = unitTestingConfigLoader({ appFullPath, projectRoot, angular, rootPagesRegExp: registerModules }); @@ -75,3 +76,6 @@ module.exports = function (source, map) { this.callback(null, source, map); }; + + +export default loader; \ No newline at end of file diff --git a/jasmine-config/jasmine.json b/jasmine-config/jasmine.json index 84db3eb2..8d3ecdc5 100644 --- a/jasmine-config/jasmine.json +++ b/jasmine-config/jasmine.json @@ -1,7 +1,8 @@ { "spec_dir": ".", "spec_files": [ - "./!(node_modules)/**/*.spec.js", + "!node_modules/**/*.spec.js", + "!demo/**/*.spec.js", "./*.spec.js" ], "helpers": [ diff --git a/package.json b/package.json index f5bce176..4fd70f85 100644 --- a/package.json +++ b/package.json @@ -77,12 +77,15 @@ "@angular/compiler-cli": "8.0.0", "@ngtools/webpack": "8.0.0", "@types/jasmine": "^3.3.7", + "@types/loader-utils": "^1.1.3", "@types/node": "^10.12.12", "@types/proxyquire": "1.3.28", "@types/semver": "^6.0.0", + "@types/webpack": "^4.4.34", "conventional-changelog-cli": "^1.3.22", "jasmine": "^3.2.0", "jasmine-spec-reporter": "^4.2.1", + "loader-utils": "^1.2.3", "proxyquire": "2.1.0", "typescript": "~3.4.0" } From f8312dec87663325b675d08ca1a1092ce7777f60 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 2 Jul 2019 17:26:36 +0300 Subject: [PATCH 03/10] chore: vs code tasks --- .vscode/launch.json | 10 ++++++++++ .vscode/tasks.json | 13 +++++++++++++ package.json | 5 +++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index d77d2b08..3cd1efa9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,16 @@ "args": [ "--env.android", "--env.aot" ], "runtimeArgs": [ "--preserve-symlinks" ], "stopOnEntry": true, + }, + { + "type": "node", + "request": "launch", + "name": "TypeScriptApp Webpack", + "cwd": "${workspaceFolder}/demo/TypeScriptApp", + "program": "${workspaceFolder}/demo/TypeScriptApp/node_modules/.bin/webpack", + "args": [ "--env.android" ], + "stopOnEntry": true, + "preLaunchTask": "npm:tsc" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..79199e22 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label":"npm:tsc", + "type": "npm", + "script": "tsc", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 4fd70f85..3c41ef81 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,11 @@ "url": "https://github.com/NativeScript/nativescript-dev-webpack.git" }, "scripts": { + "tsc": "tsc", "postinstall": "node postinstall.js", "preuninstall": "node preuninstall.js", "postpack": "rm -rf node_modules", - "prepare": "tsc && npm run jasmine", + "prepare": "npm run tsc && npm run jasmine", "test": "npm run prepare && npm run jasmine", "jasmine": "jasmine --config=jasmine-config/jasmine.json", "version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md" @@ -49,8 +50,8 @@ "clean-webpack-plugin": "~1.0.0", "copy-webpack-plugin": "~4.6.0", "css-loader": "~2.1.1", - "fork-ts-checker-webpack-plugin": "1.3.0", "extra-watch-webpack-plugin": "1.0.3", + "fork-ts-checker-webpack-plugin": "1.3.0", "global-modules-path": "2.0.0", "minimatch": "3.0.4", "nativescript-hook": "0.2.4", From 14145bec27c6f20b6325a8460a3f54304d8b610a Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 2 Jul 2019 23:31:38 +0300 Subject: [PATCH 04/10] chore: convert hmr folder to TS --- .gitignore | 12 ++++-------- hmr/hmr-update.js | 7 ------- hmr/hmr-update.ts | 11 +++++++++++ hmr/index.js | 1 - hmr/index.ts | 1 + 5 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 hmr/hmr-update.js create mode 100644 hmr/hmr-update.ts delete mode 100644 hmr/index.js create mode 100644 hmr/index.ts diff --git a/.gitignore b/.gitignore index 0d149819..8f8de90d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,38 +2,34 @@ node_modules *.tgz package-lock.json +*.js.map plugins/NativeScriptAngularCompilerPlugin.d.ts plugins/NativeScriptAngularCompilerPlugin.js -plugins/NativeScriptAngularCompilerPlugin.js.map transformers/*.d.ts transformers/*.js -transformers/*.js.map utils/*.d.ts utils/*.js -utils/*.js.map + +hmr/*.d.ts +hmr/*.js plugins/PlatformFSPlugin.d.ts plugins/PlatformFSPlugin.js -plugins/PlatformFSPlugin.js.map plugins/WatchStateLoggerPlugin.d.ts plugins/WatchStateLoggerPlugin.js -plugins/WatchStateLoggerPlugin.js.map host/resolver.d.ts host/resolver.js -host/resolver.js.map jasmine-config/reporter.d.ts jasmine-config/reporter.js -jasmine-config/reporter.js.map bundle-config-loader.d.ts bundle-config-loader.js -bundle-config-loader.js.map **/*.spec.js* **/*.spec.d.ts* diff --git a/hmr/hmr-update.js b/hmr/hmr-update.js deleted file mode 100644 index 9536d4fe..00000000 --- a/hmr/hmr-update.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = () => { - const update = require("../hot"); - const fileSystemModule = require("tns-core-modules/file-system"); - const applicationFiles = fileSystemModule.knownFolders.currentApp(); - const latestHash = __webpack_require__["h"](); - return update(latestHash, filename => applicationFiles.getFile(filename)); -} \ No newline at end of file diff --git a/hmr/hmr-update.ts b/hmr/hmr-update.ts new file mode 100644 index 00000000..8dcbb6c6 --- /dev/null +++ b/hmr/hmr-update.ts @@ -0,0 +1,11 @@ + +import update from "../hot"; +import { knownFolders } from "tns-core-modules/file-system"; + +declare const __webpack_require__: any; + +export function hmrUpdate() { + const applicationFiles = knownFolders.currentApp(); + const latestHash = __webpack_require__["h"](); + return update(latestHash, filename => applicationFiles.getFile(filename)); +} \ No newline at end of file diff --git a/hmr/index.js b/hmr/index.js deleted file mode 100644 index bdda024f..00000000 --- a/hmr/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.hmrUpdate = require("./hmr-update"); \ No newline at end of file diff --git a/hmr/index.ts b/hmr/index.ts new file mode 100644 index 00000000..24abe3c0 --- /dev/null +++ b/hmr/index.ts @@ -0,0 +1 @@ +export { hmrUpdate } from "./hmr-update"; \ No newline at end of file From ebc7029193a72c25721f31cf99bc4a37f94d8157 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 2 Jul 2019 23:32:00 +0300 Subject: [PATCH 05/10] feat: universal hmr loader --- hmr/hot-loader.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 hmr/hot-loader.ts diff --git a/hmr/hot-loader.ts b/hmr/hot-loader.ts new file mode 100644 index 00000000..38a95100 --- /dev/null +++ b/hmr/hot-loader.ts @@ -0,0 +1,36 @@ +import { loader } from "webpack"; +import { convertToUnixPath } from "../lib/utils"; +import { extname } from "path"; + +const extMap = { + ".css" : "style", + ".scss" : "style", + ".less" : "style", + ".js" : "script", + ".ts" : "script", + ".xml" : "markup", + ".html" : "markup", +} + +const loader: loader.Loader = function (source, map) { + const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); + const modulePath = convertToUnixPath(moduleRelativePath); + const ext = extname(modulePath).toLowerCase(); + const typeStyle = extMap[ext] || "unknown"; + + const hotCode = ` +if (module.hot && global._shouldAutoAcceptModule && global._shouldAutoAcceptModule(module.id)) { + console.log("AUTO ACCEPT MODULE: ", module.id, '${modulePath}') + module.hot.accept(); + module.hot.dispose(() => { + global.hmrRefresh({ type: '${typeStyle}', path: '${modulePath}' }); + }) +}`; + + this.callback(null, `${source};${hotCode}`, map); +}; + +export default loader; + + + From 128c474ac454f5baf5937eeb469b21d7603b26ff Mon Sep 17 00:00:00 2001 From: vakrilov Date: Thu, 4 Jul 2019 13:35:22 +0300 Subject: [PATCH 06/10] feat: no need of "page" suffix for HMR to work --- bundle-config-loader.ts | 7 ++++-- demo/AngularApp/webpack.config.js | 1 - demo/JavaScriptApp/webpack.config.js | 19 ++++------------- demo/TypeScriptApp/webpack.config.js | 17 +++------------ hmr/hot-loader.ts | 32 +++++++++++++++++----------- templates/webpack.angular.js | 1 - templates/webpack.javascript.js | 15 ++----------- templates/webpack.typescript.js | 17 +++------------ templates/webpack.vue.js | 3 +-- 9 files changed, 38 insertions(+), 74 deletions(-) diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index 8de5d694..e28f7777 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -2,6 +2,9 @@ import unitTestingConfigLoader from "./unit-testing-config-loader"; import { loader } from "webpack"; import { getOptions } from "loader-utils"; +// Matches all source, markup and style files that are not in App_Resources +const defaultMatch = /(? { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index b6c0e6d1..2ba03f9c 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -28,7 +28,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -103,7 +102,7 @@ module.exports = env => { '~': appFullPath }, // don't resolve symlinks to symlinked modules - symlinks: false + symlinks: true }, resolveLoader: { // don't resolve symlinks to symlinked loaders @@ -180,18 +179,8 @@ module.exports = env => { }, { - test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(js|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, @@ -234,7 +223,7 @@ module.exports = env => { platforms, }), // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), + new nsWebpack.WatchStateLoggerPlugin() ], }; diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 2ae69690..6673a849 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -29,7 +29,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -186,18 +185,8 @@ module.exports = env => { }, { - test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(ts|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, @@ -265,7 +254,7 @@ module.exports = env => { async: false, useTypescriptIncrementalApi: true, memoryLimit: 4096 - }), + }) ], }; diff --git a/hmr/hot-loader.ts b/hmr/hot-loader.ts index 38a95100..5d823bdb 100644 --- a/hmr/hot-loader.ts +++ b/hmr/hot-loader.ts @@ -1,15 +1,16 @@ import { loader } from "webpack"; import { convertToUnixPath } from "../lib/utils"; import { extname } from "path"; +import { getOptions } from "loader-utils"; const extMap = { - ".css" : "style", - ".scss" : "style", - ".less" : "style", - ".js" : "script", - ".ts" : "script", - ".xml" : "markup", - ".html" : "markup", + ".css": "style", + ".scss": "style", + ".less": "style", + ".js": "script", + ".ts": "script", + ".xml": "markup", + ".html": "markup", } const loader: loader.Loader = function (source, map) { @@ -18,16 +19,23 @@ const loader: loader.Loader = function (source, map) { const ext = extname(modulePath).toLowerCase(); const typeStyle = extMap[ext] || "unknown"; + const options = getOptions(this) || {}; + const alwaysSelfAccept = options.alwaysSelfAccept; + const trace = options.trace; + + const shouldAutoAcceptCheck = `&& global._isModuleLoadedForUI && global._isModuleLoadedForUI("${modulePath}")`; + const traceCode = `console.log("[hot-loader]: Self-accept module: ${modulePath}");`; + const hotCode = ` -if (module.hot && global._shouldAutoAcceptModule && global._shouldAutoAcceptModule(module.id)) { - console.log("AUTO ACCEPT MODULE: ", module.id, '${modulePath}') +if (module.hot ${alwaysSelfAccept ? "" : shouldAutoAcceptCheck} ) { + ${trace ? traceCode : ""} module.hot.accept(); module.hot.dispose(() => { - global.hmrRefresh({ type: '${typeStyle}', path: '${modulePath}' }); - }) + global.hmrRefresh({ type: "${typeStyle}", path: "${modulePath}" }); + }); }`; - this.callback(null, `${source};${hotCode}`, map); + this.callback(null, `${source}; ${hotCode} `, map); }; export default loader; diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 22b0b558..f2933c5f 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -32,7 +32,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index a756fbcf..e6515456 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -27,7 +27,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -179,18 +178,8 @@ module.exports = env => { }, { - test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(js|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 2f60c565..8c7627bf 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -28,7 +28,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -183,20 +182,10 @@ module.exports = env => { }, ].filter(loader => !!loader) }, - - { - test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.ts$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - + { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(ts|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 52a98979..df96d8e1 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -31,7 +31,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -265,7 +264,7 @@ module.exports = env => { if (unitTesting) { config.module.rules.push( { - test: /-page(\.(land|port|phone|tablet|minH\d+|minW\d+|minWH\d+))?\.js$/, + test: /-page\.js$/, use: "nativescript-dev-webpack/script-hot-loader" }, { From 10aabe6baffe9544b27d11fa2c1c72603a9c7f61 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Thu, 4 Jul 2019 16:27:03 +0300 Subject: [PATCH 07/10] chore: add tns-core-modules as dev dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3c41ef81..8004580e 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "jasmine-spec-reporter": "^4.2.1", "loader-utils": "^1.2.3", "proxyquire": "2.1.0", + "tns-core-modules": "next", "typescript": "~3.4.0" } } From 9fce77de0f53848c1e97318cc5983f7b29892d0e Mon Sep 17 00:00:00 2001 From: vakrilov Date: Fri, 5 Jul 2019 16:49:56 +0300 Subject: [PATCH 08/10] fix: filter d.ts files --- bundle-config-loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index e28f7777..da7d4196 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -3,7 +3,7 @@ import { loader } from "webpack"; import { getOptions } from "loader-utils"; // Matches all source, markup and style files that are not in App_Resources -const defaultMatch = /(? Date: Fri, 5 Jul 2019 16:50:59 +0300 Subject: [PATCH 09/10] refactor: don't include native app/activity in bundle --- demo/JavaScriptApp/webpack.config.js | 1 + demo/TypeScriptApp/webpack.config.js | 1 + 2 files changed, 2 insertions(+) diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index 2ba03f9c..27bfc2db 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -173,6 +173,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + registerModules: /(? !!loader) diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 6673a849..88f3585f 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -179,6 +179,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + registerModules: /(? !!loader) From 9e093f01f69d697092af15aeb8a3600515a9bc15 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Fri, 5 Jul 2019 16:59:57 +0300 Subject: [PATCH 10/10] refactor: review changes --- hmr/hmr-update.ts | 1 - hmr/hot-loader.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hmr/hmr-update.ts b/hmr/hmr-update.ts index 8dcbb6c6..5f29792d 100644 --- a/hmr/hmr-update.ts +++ b/hmr/hmr-update.ts @@ -1,4 +1,3 @@ - import update from "../hot"; import { knownFolders } from "tns-core-modules/file-system"; diff --git a/hmr/hot-loader.ts b/hmr/hot-loader.ts index 5d823bdb..2a0fca71 100644 --- a/hmr/hot-loader.ts +++ b/hmr/hot-loader.ts @@ -17,7 +17,7 @@ const loader: loader.Loader = function (source, map) { const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); const modulePath = convertToUnixPath(moduleRelativePath); const ext = extname(modulePath).toLowerCase(); - const typeStyle = extMap[ext] || "unknown"; + const moduleType = extMap[ext] || "unknown"; const options = getOptions(this) || {}; const alwaysSelfAccept = options.alwaysSelfAccept; @@ -31,7 +31,7 @@ if (module.hot ${alwaysSelfAccept ? "" : shouldAutoAcceptCheck} ) { ${trace ? traceCode : ""} module.hot.accept(); module.hot.dispose(() => { - global.hmrRefresh({ type: "${typeStyle}", path: "${modulePath}" }); + global.hmrRefresh({ type: "${moduleType}", path: "${modulePath}" }); }); }`;