Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs code IntelliSense not working with webpack bundles

I have a simple webpack config .

const path = require('path');

module.exports = {
  devtool: 'source-map',
  entry: './src/index.js',
  output: {
    libraryTarget: 'commonjs',
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

After I build and upload my modules to npm and use them on other projects the vs code IntelliSense is not working for these modules. The module functions are documented with jsdoc.

import { myFunc } from 'myModule';

Or

const myModule = require('myModule');

Myfunc and myModule have no IntelliSense auto complate support or any other.

How can I keep the jsdoc working after webpack build?

like image 238
kailniris Avatar asked Nov 08 '22 18:11

kailniris


1 Answers

If the package is coming through npm, you need to publish a type definition file (.d.ts). d.ts files contain type definitions and comments for your API that allow us to efficiently provide rich intellisense for external packages. VS Code is limited in how it can parse the actual JS code from node_modules packages.

Here's some resources on getting started with d.ts files:

  • Overview of how VSCode's JS intellisense works: https://code.visualstudio.com/Docs/languages/javascript#_intellisense
  • Writing and publishing a d.ts files: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
like image 151
Matt Bierner Avatar answered Nov 14 '22 22:11

Matt Bierner