uniapp vue3.0 introduces external js (sdk) files through import undefined

During the process of using uniapp to import the SDK, you may encounter such a situation: when using console.log() to print the name of the imported module, the actual output name is not the name you expected. This is because after uniapp is compiled and packaged, the code will be renamed to reduce file size and improve execution efficiency, including modifying variable names, method names, module names, etc.

uniapp vue2.0 introduces external js (sdk) files through import, normal
uniapp vue3.0 introduces external js (sdk) files through import, and reports an error of undefined


import sdk from './juphoon-sdk'
console.log('sdk', sdk)

Reason after uniapp is compiled
insert image description here
:
When using uniapp to introduce a third-party library or module, if the import name is not specified, in order to avoid naming conflicts, the applet compilation tool will add a rename in front of the name, which will cause the method to not be found
insert image description here
Solution:
Create a vue.config.js file and add the following configuration:

module.exports = {
    
    
  configureWebpack: {
    
    
    output: {
    
    
      "filename": "[name].js",
      "library": "[name]",
      "libraryTarget": "umd"
    }
  }
}

insert image description here

Quoting from the page:

import JuphoonWeChatConference from '../common/juphoon-sdk'
console.log('JuphoonWeChatConference页面使用', JuphoonWeChatConference)

insert image description here
Although the name is still supplemented with a rename, the sdk method can get
insert image description here

Guess you like

Origin blog.csdn.net/m0_47791238/article/details/130948718