Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parceljs import javascript file as string

I have a very particular use case. I want to import a javascript file as a string and inject it into html responses at will in a service worker. I can't see how to do this using parceljs beyond hosting the javascript file somewhere and doing fetch at runtime to load the js file into memory. However, I want to do this at build time. How best to do this?

Note: Ideally the dependencies of javascript file I am importing should be bundled into the string.

like image 823
david_adler Avatar asked Jul 14 '26 11:07

david_adler


1 Answers

Seems to be possible in parcel 2 with

import js from "bundle-text:./b.ts";

console.log(js);

https://v2.parceljs.org/configuration/plugin-configuration/#predefined-(offical)-named-pipelines

like image 63
david_adler Avatar answered Jul 15 '26 23:07

david_adler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!