This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
refactor: HMR and webpack improvements #966
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b5aa36
feat: support for file qualifiers
fd48b8a
refactor: convert bundle-config-loader to TS
f8312de
chore: vs code tasks
14145be
chore: convert hmr folder to TS
ebc7029
feat: universal hmr loader
128c474
feat: no need of "page" suffix for HMR to work
10aabe6
chore: add tns-core-modules as dev dep
9fce77d
fix: filter d.ts files
ed7671a
refactor: don't include native app/activity in bundle
9e093f0
refactor: review changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
.vscode/tasks.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
hmr/hmr-update.js
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
hmr/hmr-update.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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)); | ||
} |
44 changes: 44 additions & 0 deletions
hmr/hot-loader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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", | ||
} | ||
|
||
const loader: loader.Loader = function (source, map) { | ||
const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); | ||
const modulePath = convertToUnixPath(moduleRelativePath); | ||
const ext = extname(modulePath).toLowerCase(); | ||
const moduleType = 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 ${alwaysSelfAccept ? "" : shouldAutoAcceptCheck} ) { | ||
${trace ? traceCode : ""} | ||
module.hot.accept(); | ||
module.hot.dispose(() => { | ||
global.hmrRefresh({ type: "${moduleType}", path: "${modulePath}" }); | ||
}); | ||
}`; | ||
|
||
this.callback(null, `${source}; ${hotCode} `, map); | ||
}; | ||
|
||
export default loader; | ||
|
||
|
||
|
1 change: 0 additions & 1 deletion
hmr/index.js
Oops, something went wrong.
1 change: 1 addition & 0 deletions
hmr/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { hmrUpdate } from "./hmr-update"; |
3 changes: 2 additions & 1 deletion
jasmine-config/jasmine.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.