crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.71k stars 181 forks source link

jquery in content_scripts load #493

Open yuxinyu12345 opened 2 years ago

yuxinyu12345 commented 2 years ago

Build tool

Vite

Where do you see the problem?

Describe the bug

"content_scripts": [ { "js": [ "src/lib/jquery-3.3.1.min", "src/index.js" ], "matches": [ "://.baidu.com/*" ] } ]

The dev environment can use $, but the build dist cannot.

Reproduction

Error in event handler: ReferenceError: $ is not defined at e (chrome-extension://omedgkhbnladahaodjdiojnbmiablmip/assets/index.js.561d4845.js:1:104)

test demo https://github.com/yuxinyu12345/crxjs-demo

Logs

No response

System Info

"dependencies": {
    "vue": "^3.2.37"
  },
  "devDependencies": {
    "@crxjs/vite-plugin": "^1.0.14",
    "@vitejs/plugin-vue": "^3.0.3",
    "typescript": "^4.6.4",
    "vite": "^3.0.7",
    "vue-tsc": "^0.39.5"
  }

Severity

blocking an upgrade

yuxinyu12345 commented 1 year ago

i solved the problem. use not import $ from 'jquery',because i use local files. The solution is as follows:

  1. execute yarn add jquery
  2. vite.config-build-minify: false, close minify
jacksteamdev commented 1 year ago

Vite/CRXJS only support ES modules currently, but support for plain script files like JQuery is on the roadmap.

yuxinyu12345 commented 1 year ago

Vite/CRXJS only support ES modules currently, but support for plain script files like JQuery is on the roadmap.

Thank you for your reply