mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-23 23:11:12 +02:00
add implicit type="module" support
This commit is contained in:
@@ -432,7 +432,12 @@ export function getCompleteHtml(html, css, js, item, isForExport) {
|
|||||||
|
|
||||||
if (js) {
|
if (js) {
|
||||||
if (typeof js === 'string') {
|
if (typeof js === 'string') {
|
||||||
contents += js ? '<script>' + js + '\n//# sourceURL=userscript.js' : '';
|
const importRegex =
|
||||||
|
/^\s*import\s+(?:(?:\w+\s*,?\s*(?:\{[^}]*\})?\s*from\s*)?['"][^'"]+['"]|(?:\{[^}]*\}|\*\s+as\s+\w+)\s+from\s+['"][^'"]+['"])/m;
|
||||||
|
const hasImport = importRegex.test(js);
|
||||||
|
contents += js
|
||||||
|
? `<script${hasImport ? ' type="module"' : ''}>${js}\n//# sourceURL=userscript.js`
|
||||||
|
: '';
|
||||||
} else {
|
} else {
|
||||||
var origin = chrome.i18n.getMessage()
|
var origin = chrome.i18n.getMessage()
|
||||||
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`
|
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`
|
||||||
|
Reference in New Issue
Block a user