Closed raphael-bresson closed 3 years ago
Raphael,
you have 2 options:
tools.js
into tools.mjs
getFile()
option to make vue3-sfc-loader understand .js
as .mjs
file. See https://github.com/FranckFreiburger/vue3-sfc-loader/discussions/12#discussioncomment-255331Ok great, thank you for your answer ! I chose option 2 which worked smoothly
async getFile(url) {
const res = await fetch(url);
if (!res.ok)
throw Object.assign(new Error(url + " " + res.statusText), { res });
let content = await res.text();
content = url.endsWith("/tools.js")
? { content: content, type: ".mjs" } // `type` since v0.7.0 and `extname` before
: content;
return content;
},
return {content: content, type: ".mjs"}
After the updates is there a new solution for this?
After the updates is there a new solution for this?
vue3-sfc-loader v0.8.3 for vue2
is my options:
const options = {
moduleCache: {vue: Vue},
getFile(url) {
url = /.*?\.js|.mjs|.css|.less|.vue$/.test(url) ? url : `${url}.vue`
const type = /.*?\.js|.mjs$/.test(url) ? ".mjs" : /.*?\.vue$/.test(url) ? '.vue' : /.*?\.css$/.test(url) ? '.css' : '.vue';
const getContentData = asBinary => fetch(url).then(res => !res.ok ? Promise.reject(url) : asBinary ? res.arrayBuffer() : res.text())
return {getContentData: getContentData, type: type}
},
addStyle(textContent) {
let styleElement = document.createElement('style');
document.head.insertBefore(Object.assign(styleElement, {textContent}),
document.head.getElementsByTagName('style')[0] || null);
},
handleModule(type, getContentData, path, options) {
switch (type) {
case '.css':
return options.addStyle(getContentData(false));
case '.less':
console.error('.......')
}
},
log(type, ...args) {
console.log(type, ...args);
}
};
After the updates is there a new solution for this?
https://github.com/FranckFreiburger/vue3-sfc-loader/issues/92
Hi, First I wan't to thank you for this librairy which is going to be very useful for me. I can't manage to import from a module inside a
script
tag of a .vue file For example :The line
_import { label } from "./../tools.js";_
raises the following error.
_'import' and 'export' may appear only with 'sourceType: "module"' (2:0)_
I tried adding
type="module"
to thescript
tag but it didn't work either.Is it possible to do that ? How ? Thank you for your answer
Raphael