1

So I am quite simply looking at how I can do a regular import e.g.

import { something } from 'myfantastic/package';

or even in a case:

import 'myfantastic/package/js/something.js';

I know I can do this within my <script> tag as a normal import but what I am trying to do is load a free package or pro package based on an env variable.

So I would like to be able do something like the following:

export default {
    created() {
        const something = ({something}) => import('myfantastic/package');
        something.add( data )
    }   
}

If possible I would like to be able to do this for standard scripts e.g. 'myfantastic/package/js/something.js'; and CSS files e.g. 'myfantastic/package/css/style.css'.

How can I achieve this?

seb14717
  • 135
  • 8
  • 1
    Does this answer your question? [Importing javascript file for use within vue component](https://stackoverflow.com/questions/48426972/importing-javascript-file-for-use-within-vue-component) – Sphinx Sep 23 '20 at 17:28
  • No it doesn't, I'm trying to load it programmatically within my vue component rather than make it accessible to it. – seb14717 Sep 23 '20 at 18:14
  • checkout [lazyload](https://router.vuejs.org/guide/advanced/lazy-loading.html) it may help you – Joseph Sep 23 '20 at 18:39
  • You can use [dynamic imports](https://v8.dev/features/dynamic-import), at this point they're pretty [well supported](https://caniuse.com/es6-module-dynamic-import) – Jared Smith Sep 23 '20 at 18:45

0 Answers0