[FeatureRequest] Allow to import javascript modules
Question
When using Ionic StencilJS, the components are imported using the new module support:
<script type="module" src="http://localhost:3333/build/grapejspoc.esm.js"></script>
<script nomodule="" src="http://localhost:3333/build/grapejspoc.js"></script>
On {canvas: scripts: []} I can only load external scripts by their url.
To cover such case, we could import modules as this:
canvas: {
scripts: [
{ src: "https://pagecdn.io/lib/jquery/3.4.1/jquery.min.js", integrity: "sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=", crossorigin="anonymous" },
{ type: "module", src: "https://bla/bla.esm.js"},
{ nomodule: "", src: "https://bla/bla.js" }
]
}
The final result inside canvas would be:
<script src="https://pagecdn.io/lib/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script type="module" src="http://bla/bla.esm.js"></script>
<script nomodule="" src="http://bla/bla.js"></script>
Notice that this would cover also the case when we want to use integrity or crossorigin in <script> tags and, of course, inserting a url string would still work as it is today.
Answers (3)
Nice I like it, for anyone interested in making a PR the code to update is here: https://github.com/artf/grapesjs/blob/aee18dcf0602e5d56e7670deb8d4ffbf31c73008/src/canvas/view/CanvasView.js#L140-L161
Hi can I start from yours code to init grapesjs not in the html file but in a separated js file? Thank you
@artf it looks like this feature has been implemented. There is a minor issue where type will default to 'text/javascript'. For HTML 5 it should be omitted but should not cause any issues if there.
Should this issue be closed?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4323
BUG: Performance issue while dragging component to canvas when you have 2k component on canvas
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Google Chrome Version 101.0.4951.41 (Officia...
Issue #1936
Absolute/Designer mode
Hi guys, this issue is an overview of what is it, what is done, what to do and nice-to-have to complete the Designer Mode feature.Preface S...
Issue #3267
BUG: Cannot set 0px box shadow blur
For some reason, the editor does not allow to set the blur to 0px. 0 always magically turns into 5px. <img width="243" alt="Screenshot 2021...
Issue #761
Text component problem
Hi. I wish a text component that do not create new components every time I press "Enter" key to create new paragraphs (this is a bad usabil...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.