javascript - JS library conversion problem from script reference to using import
ringa_lee
ringa_lee 2017-05-19 10:47:36
0
1
537

Maybe the title is not very clear, I will explain in detail:

I rely on a jq component in a project. It is referenced through a script tag. How can I make it available through the import method?

https://www.npmjs.com/package/particles.js

This is the library above. I changed the part where I forgot to hang a function on the window to export default. I found that an error will be reported. How can I modify this so that I can use import?

window.particlesJS.load = function(tag_id, path_config_json, callback){
    code ...
}

//这里我加了

export defalut particlesJS;

I found that it is not possible. What did I do wrong?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
阿神

Install into node_module

npm install particles.js

Quote (in entry file)

import 'particles.js'

If this jq component needs to call jq methods or use jq objects, jq must also be installed and exposed to the world

npm install jquery@xxx

Exposed to the overall situation, I use webpack here, and the rest is up to you - -

        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            'window.$': 'jquery'
        })
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template