1

Let's say there is component ComponentA and I am importing libA in it.

import libA from 'libA'

and libA needs libB loaded. it works with If I load them in html:

<script url='libB url'/>
<script url='libA url'/>

But I'd like to import it in ComponentA. I am new on ES6, webpack, babel, vue and components. Any help would be appreciated!

1 Answer 1

1

You can’t import files from external URLs. Using external javascript files in a .js file You can download the external script and Import or require them into your vue component or place them in your html file as a script tag.

I'm assuming you also mean <script src='libB url' /> not <script url='libB url' />

-- edit ---

You can also use webpack plugins in your build/webpack.prod.conf.js and build/webpack.dev.conf.js. For example if your libB is jQuery for example you can add the following under your plugins array

new webpack.ProvidePlugin({
  $: 'jquery',
  jquery: 'jquery',
  'window.jQuery': 'jquery',
  jQuery: 'jquery',
}),
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. actually the libraries are also in my package.json and node_modules. Yes right src :) sorry my bad
You can also in your 'webpack.prod.conf.js' and 'webpack.dev.conf.js' a new webpack plugin with the library as a global variable. new webpack.ProvidePlugin({ $: 'jquery', jquery: 'jquery', 'window.jQuery': 'jquery', jQuery: 'jquery', Ladda: 'ladda', ladda: 'ladda', PNotify: 'PNotify' }),
Thank you very much. I successfully imported threejs usind ur method but there is panolens library github.com/pchen66/panolens.js/blob/master/build/panolens.js which is not exportable :( How can I deal with this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.