'How to config Vite build output that can run with <script type="text/javascript"></script>
How can I config Vite build to output with script type="text/javascript"
I'm using Vite 2.7.2, when finished building the code in HTML output the script tag as follow
<script type="module" crossorigin src="/assets/index.0c37d7b4.js"></script>
What I want is
<script type="text/javascript" crossorigin src="/assets/index.0c37d7b4.js"></script>
The code run fine with type="module" but when I manually replace it with type="text/javascript" the code break and output following error
Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
Here is the original code before building
const elements = {
root: document.querySelector('#root'),
};
elements.root.innerHTML = `Loading...`;
The reason I want the type to be type="text/javascript" because Shopify platform only accept script with type "text/javascript"
Solution 1:[1]
I'm having a similar issue. Recently I migrated a React project from CRA to Vite, and I am using a minified version of cryptico.js. When using the tag "text/javascript" to import the script, it works fine in development, but when compiling to production, the script is not moved to the "dist" folder, thus the system fails.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Matias |