plasmo icon indicating copy to clipboard operation
plasmo copied to clipboard

[BUG] with-web-accessible-resources

Open crazyair opened this issue 3 years ago • 4 comments

What happened?

image

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

No response

Relevant log output

No response

(OPTIONAL) Contact Details

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] I checked the current issues for duplicate problems.

crazyair avatar Jul 02 '22 13:07 crazyair

import test from "./resources/test.json"

crazyair avatar Jul 02 '22 14:07 crazyair

Yup, this will be fixed once https://github.com/parcel-bundler/parcel/pull/8269 is merged

louisgv avatar Jul 02 '22 16:07 louisgv

Just BTW, you can also import the raw JSON like you have already done (i.e. it will be loaded as a JavaScript object).

import test from './resources/test.json';
console.log(test); // { "your": { "json": "here" } }

Alternatively you can import it as a link without even adding it to web_accessible_resources: Parcel will add it for you under the hood.

import testURL from 'url:./resources/test.json';

console.log(testURL); // chrome-extension://very_long_id/test.[hash].json
fetch(testURL).then(res => res.json()).then(console.log); // { "your": { "json": "here" } }

101arrowz avatar Jul 02 '22 18:07 101arrowz

Just BTW, you can also import the raw JSON like you have already done (i.e. it will be loaded as a JavaScript object).

import test from './resources/test.json';
console.log(test); // { "your": { "json": "here" } }

Alternatively you can import it as a link without even adding it to web_accessible_resources: Parcel will add it for you under the hood.

import testURL from 'url:./resources/test.json';

console.log(testURL); // chrome-extension://very_long_id/test.[hash].json
fetch(testURL).then(res => res.json()).then(console.log); // { "your": { "json": "here" } }

Note: this is a good substitute for static importing. However, when an extension wants to provide a webpage with extra resource file to fetch (via the chrome:// protocol), it will not be a valid substitution.

louisgv avatar Jul 03 '22 03:07 louisgv