vrimar / construct-ui

A Mithril.js UI library
https://vrimar.github.io/construct-ui
MIT License
287 stars 23 forks source link

Question: CUI (from include of .min.js) with intellisense in VSCode #78

Closed jdiderik closed 1 year ago

jdiderik commented 1 year ago

I have been struggling to get intellisense working (autocomplete) in VSCode when using the construct-ui.min.js as an include in my HTML file, while using modern modules in the rest off the application.

For example, when in the code below you type: 'CUI.' the autocomplete should prompt options, like Button, ButtonGroup etc.

file: /modules/myView.js

const myView = {
    view: () => {
        return m(CUI.Button, { label: 'My button label' })
    }
}
export default myView;

This works as expected when using import * as CUI from "construct-ui" But this then fails in the browser, since it can't resolve NodeJS module references like this and you would need a compiler (like parceljs, rollup, babel etc.) which we do not want (which will bloat the module file (that are conditionally imported by the browser)

Any thoughts on this? how to setup jsconfig.json and/or package.json and/or tsconfig.json and/or globals.d.ts or anything... cannot seem to figure this one out.

vrimar commented 1 year ago

I have bundled a single typescript declaration file in v0.3.4.

Include the path to the declaration file in your jsconfig.json:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
  },
  "include": [
    "src",
    "node_modules/construct-ui/lib/cui.d.ts" <------
  ]
}
jdiderik commented 1 year ago

Tkan you @vrimar very much, this works out great! Much appriciated