How to use aliases in VSCode extension development

  1. Typescript compilation
  2. Webpack packaging
  3. Test build
  1. tsconfig.json
  2. webpack.config.js
  3. package.json — well, that’s where you can put the initial alias configuration.
npm i — save-dev module-alias @types/module-alias
tsconfig.json
webpack.config.js
package.json
package.json
“@src/*”: “src/*”
“@languageServer”: “src/lib/languageServer”
const tsconfigContent = require('./tsconfig.json');const alias = {}Object.entries(tsconfigContent.compilerOptions.paths).forEach(
([aliasName, [ aliasContent ]]) => {
const name = aliasName.replace('/*', '');
const aliasPath = path.resolve(
root,
'out',
aliasContent.replace('/*', '')
);
alias[name] = aliasPath;
}
)
webpack.config.js
import * as moduleAlias from 'module-alias';
import * as path from 'path';
const tsconfigContent = require('../../tsconfig.json');
const paths = tsconfigContent.compilerOptions.paths;
const extensionRoot = path.resolve(__dirname, '..', '..');
Object.entries(paths).forEach(
([aliasName, aliasContentList]: [string, unknown]) => {
const [aliasContent] = aliasContentList as string[];
const name = aliasName.replace('/*', '');
const aliasPath = path.resolve(
extensionRoot,
'out',
aliasContent.replace('/*', '')
);
moduleAlias.addAlias(name, aliasPath);
}
);
“@src/*”: “src/*”
“@src”: “out/src”

--

--

--

Salesforce Craftsman | Moscow Salesforce User Group Leader | https://www.salesforcecraft.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

BootstrapVue — Drop-Down Customization

Look for Code Smells in JavaScript

How to Disable Dragging an Image from an HTML Page?

ES6’s Function Destructuring Assignment Is Not A Free Lunch.

How to Focus Something on the Next Render with React Hooks

How to Quickly Build Applications Using the @zowe/cli npm Package (Part 2)

Bloket add blocker web browser .

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nikita Chursin

Nikita Chursin

Salesforce Craftsman | Moscow Salesforce User Group Leader | https://www.salesforcecraft.dev

More from Medium

Moving from Visual Studio to VS Code as a .NET Developer

vsce support

Building Your First VsCode extension

Announcing the Ably VS Code Extension