quokka-alias is a Visual Studio Code extension that automatically updates your .quokka file with aliases used in the imports of the current TypeScript file. It reads aliases from the nearest tsconfig.json file in the project directory tree and adds them to the .quokka file.
Example:
import { foo } from '@/bar';
// ...The .quokka file, after running the command:
{
"aliases": {
"@/bar": "./bar"
}
}- Automatically include aliases from imports in the
.quokkafile based on yourtsconfig.jsonfile. - Compatible with TypeScript files.
- Install the Quokka.js extension if you haven't already.
- Install the alias-quokka-plugin if you haven't already.
yarn add -D alias-quokka-pluginpnpm add -D alias-quokka-pluginnpm install --save-dev alias-quokka-plugin
- Make sure you have a
.quokkafile and atsconfig.jsonfile higher up in the project directory tree than the current file and that the.quokkafile includes thealias-quokka-pluginplugin. - Install the quokka-alias extension (this extension).
Your .quokka file should look something like this:
{
"plugins": [
"alias-quokka-plugin",
// Other plugins (optional)
],
"alias": {
// Your existing aliases (optional)
},
// Other settings (optional)
}To use the command, make sure the typescript file is the currently active file and run the command Include aliases from imports in the current file in .quokka from the command palette. After running the command, the .quokka file will be updated with the aliases used in the current file based on the tsconfig.json.
Since Quokka needs to restart for this to take effect, you can use the runCommands functionality to simplify this (introduced in VSCode 1.77). If you use the Quokka.js Run once for Current File command, consider replacing your current keybinding with the following by opening the shortcuts JSON using the command: Preferences: Open Keyboard Shortcuts (JSON).
{
"key": "cmd+r", // replace with your preferred keybinding
"command": "runCommands",
"args": {
"commands": [
"quokka-alias.include-aliases",
"quokka.stopCurrent",
"quokka.runOnce"
]
},
"when": "editorLangId == typescript"
},For the interactive Quokka.js mode, you can use this:
{
"key": "cmd+k shift+i", // replace with your preferred keybinding
"command": "runCommands",
"args": {
"commands": [
"quokka-alias.include-aliases",
"quokka.stopCurrent",
"quokka.makeQuokkaFromExistingFile"
]
},
"when": "editorLangId == typescript"
},Alternatively, to set a keybinding for the command alone use the following:
{
"key": "cmd+k shift+i", // replace with your preferred keybinding
"command": "quokka-alias.include-aliases",
"when": "editorLangId == typescript"
},Given a tsconfig.json file like this:
{
"paths": {
"@/*": [
"./*",
]
}
}And a file opened in the editor:
import { foo } from '@/bar';If your .quokka file initially contains an alias like this:
{
"aliases": {
"@/qux": "./qux"
}
}After running the command, the .quokka file will be updated with the new alias:
{
"aliases": {
"@/bar": "./bar",
"@/qux": "./qux"
}
}Note: The extension does not check for dangling aliases. If an alias is removed or no longer needed, you must manually remove it from the .quokka file.
- Quokka.js extension
- A
tsconfig.jsonfile higher up in the project directory tree than the current file - A
.quokkain the same directory as thetsconfig.jsonfile
The extension currently only handles the first entry for each alias in the paths object in tsconfig.json. For example:
{
"paths": {
"@/*": [
"./*", // included
"second_path/*" // not included
],
"src/*": [
"./src/*", // included
"second_path/*" // not included
]
}
}The alias-quokka-plugin does not currently handle aliases for some setups. This extension serves as a workaround for that issue.
- Now uses the nearest
tsconfig.jsonand.quokkato resolve aliases - Now traverses the entire import tree to resolve aliases
- Initial release.
- Adds the command
quokka-alias.add-aliases:Include aliases from imports in the current file in .quokka