1

Using:

Typescript with ES6 output (target and modules)

Vue loaded from CDN

TS typings of Vue installed by NPM

I'm trying to get types working in source .ts files and still use Vue loaded by the CDN. Vue from the CDN isn't a module (and that wouldn't help either way; as I understand it, it has to be hosted by me to be importable in ES6).

The types as installed by NPM need to be imported import Vue from 'vue' , which comes up in the generated Javascript (that's in addition to the difference in Vue being global in the generated js as a non-module) and can't be resolved because it's not local on the server.

Noein
  • 522
  • 1
  • 6
  • 16

1 Answers1

1

I think you just need to add Vue as external lib in webpack config - your typings will work correctly and webpack will resolve dependency from global variable(window).

//...
externals: {
  vue: "Vue"
}
//...

So you can use import in your code for external library - import Vue from 'vue'.

See Webpack Externals.

Max Sinev
  • 5,884
  • 2
  • 25
  • 35