VS Code AMD Modular System
I am working on an e-application using TypeScript and I am facing some problems trying to figure out which module loading system to use. I've been digging around VS code (as many consider it a poster child for Electron apps done right) to better understand conventions / best ways to do certain things, and I noticed that they use AMD modules (in the tsconfig.json file under src, all parameters "module": "amd"
, "moduleResolution": "classic"
and "baseUrl": "."
set) and they seem to use calls like requirejs for certain things, like loading a URL into a BrowserWindow, where they use require.toUrl('vs/workbench/electron-browser/bootstrap/index.html');
to load the full URL.
From my (admittedly limited) understanding, this solves the problem I'm having where I compile my TypeScript (located in a directory src
) into an output directory (called out
) and then provide. js to run Electron, which means my paths for things like mainWindow.loadUrl(__dirname + '/index.html')
are suddenly pointing to out/index.html
instead of intended src/index.html
. However, when I go through the VS code project for any requirejs module reference, I cannot find anything other than the file require.d.ts
containing this code
declare var define: {
(moduleName: string, dependencies: string[], callback: (...args: any[]) => any): any;
(moduleName: string, dependencies: string[], definition: any): any;
(moduleName: string, callback: (...args: any[]) => any): any;
(moduleName: string, definition: any): any;
(dependencies: string[], callback: (...args: any[]) => any): any;
(dependencies: string[], definition: any): any;
};
declare var require: {
toUrl(path: string): string;
(moduleName: string): any;
(dependencies: string[], callback: (...args: any[]) => any, errorback?: (err: any) => void): any;
config(data: any): any;
onError: Function;
__$__nodeRequire<T>(moduleName: string): T;
};
I created a samples file containing this in my project, but when I run my rewritten JavaScript, I get an error define is not defined
. My question is, how exactly is VS Code able to use AMD modules with a standard Node module require
, seemingly not using something like requirejs, and can implement a similar pattern to solve my path issues when running passed JavaScript code from an output directory? Thank!
source to share
No one has answered this question yet
Check out similar questions: