-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
177 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "(gdb) Launch twr-wasm unit tests", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/source/unit-test/out/test.exe", | ||
"args": [], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}/source/unit-test/out/", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "gdb", | ||
"miDebuggerPath": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
}, | ||
{ | ||
"description": "Set Disassembly Flavor to Intel", | ||
"text": "-gdb-set disassembly-flavor intel", | ||
"ignoreFailures": true | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Examples", | ||
"type": "chrome", | ||
"request": "launch", | ||
"runtimeArgs": [ | ||
"--allow-file-access-from-files", | ||
"--autoplay-policy=no-user-gesture-required", | ||
"--enable-features=SharedArrayBuffer" | ||
], | ||
"file": "${workspaceFolder}/examples/index.html", | ||
"cwd": "${workspaceFolder}/examples/" | ||
} | ||
{ | ||
"name": "Examples", | ||
"type": "chrome", | ||
"request": "launch", | ||
"runtimeArgs": [ | ||
"--allow-file-access-from-files", | ||
"--autoplay-policy=no-user-gesture-required", | ||
"--enable-features=SharedArrayBuffer" | ||
], | ||
"file": "${workspaceFolder}/examples/index.html", | ||
"cwd": "${workspaceFolder}/examples/" | ||
}, | ||
{ | ||
"name": "(gdb) Launch twr-wasm unit tests", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/source/unit-test/out/test.exe", | ||
"args": [], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}/source/unit-test/out/", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "gdb", | ||
"miDebuggerPath": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
}, | ||
{ | ||
"description": "Set Disassembly Flavor to Intel", | ||
"text": "-gdb-set disassembly-flavor intel", | ||
"ignoreFailures": true | ||
} | ||
] | ||
}, | ||
], | ||
"version": "2.0.0" | ||
} |
This file contains 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 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 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 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 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 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 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,59 @@ | ||
--- | ||
title: Resolving Import Statements | ||
description: How tools like VS Code, the Parcel bundler, and Web browser's resolve import statements | ||
--- | ||
|
||
# twr-wasm Import Resolution | ||
This section covers path resolution for statements like this: | ||
~~~ | ||
import {twrWasmModule} from "twr-wasm"; | ||
~~~ | ||
|
||
It can be confusing to determine how tools like VS Code, a bundler, or a Web Browser resolve imports like "twr-wasm". This section explains how it works, using the included examples as examples. | ||
|
||
If you have installed `twr-wasm` using `npm`, most tools will automatically resolve imports by finding the `node_modules` folder. | ||
|
||
However, if you installed using `git clone`, then other steps will need to be taken. The examples are in the git repo tree, and as a result there may be no `node_modules` for the twr-wasm libraries. This will also be the case for your project, if you installed with `git clone`. | ||
|
||
## Import path resolution by the bundler | ||
A bundler will find the twr-wasm library using one of these methods: | ||
|
||
1. If twr-wasm has been installed with npm install, the bundler will find the `node_modules` folder | ||
2. Alternately, If all your scripts are in TypeScript, use `paths` entry in `tsconfig.json` (see maze example) | ||
3. Alternately, use alias option in package.json as in the helloworld example | ||
~~~ | ||
"alias": { | ||
"twr-wasm": "../../lib-js/index.js" | ||
}, | ||
~~~ | ||
|
||
In the examples, the alias entry in the `package.json` exists so that the parcel bundler can find twr-wasm. | ||
|
||
If you are using a bundler, you don't need to add a `<script type="importmap">` tag. | ||
|
||
## Import path resolution by the browser | ||
This section apples to executing your javascript without first "bundling" it. Whether execution is from the filesystem directly in a browser or using a web server. | ||
|
||
In order for the browser to locate the twr-wasm path when import is used, you can add code like this to your HTML prior to the import. You should make sure the path for twr-wasm is correct for your project (this is correct for the examples). | ||
~~~ | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"twr-wasm": "../../lib-js/index.js" | ||
} | ||
} | ||
</script> | ||
~~~ | ||
|
||
## Import resolution by VS Code and tsc | ||
VS Code Intellisense and the typescript compiler need to find modules. If twr-wasm is installed using `npm` into a `node_modules` folder, this is probably automatic. But if this is not the case, you can add a line to the `tsconfig.json` as follows (this example assumes the `tsconfig.json` is in a examples/example folder). See the maze example. | ||
~~~ | ||
"paths": { | ||
"twr-wasm": ["./../../lib-js/index"] | ||
} | ||
~~~ | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.