Problems with webpack external extension externals references

introduce zepto.min.js in index.html

//webpack.config.js
externals: {
  "zepto": "Zepto"
}

//index.js
import $ from "zepto"

if you quote it like this, you will get an error, Cannot find module "zepto"
but

//webpack.config.js
externals: {
  zepto : {
      commonjs: "Zepto",
      amd: "Zepto",
      root: "$" // 
   }
}

//index.js
window.$

that"s fine, so did I write something wrong

Dec.28,2021

may be because zepto is a non-modular library, which can only be retrieved globally by root. It is possible to replace it with jQuery.

Menu