¿Es posible usar una variable global con resumen para dar como resultado una importación relativa de un archivo en el paquete de destino? Algo como
const file = window.MY_GLOBAL;
a
const file = import(`path-to-file-in-dest`);
He visto el plugin de define
define({ replacements: { "window.MY_GLOBAL": `import ("${(path_to_file_in_dest`)}")`, }, }), pero obtiene Error SyntaxError: Unexpected token (1:12)
Intentando también con el complemento de replace :
// rollup.config.js const externalFile = path.resolve("./myJsonFile.json"); plugins: [ typescript(), json(), resolve(), commonjs(), replace({ MY_JSON_FILE: externalFile, preventAssignment: true, }), ...], //myCode.ts export const MY_JSON_FILE = ""; import(MY_JSON_FILE) .then((data) => { window.X = data; console.debug(window.X); }) .catch((error) => { console.error(`Unable to find file`,error); return; }); pero sigue recibiendo un error cuando se rollup -c
(!) Plugin typescript: @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.y cuando cambio el "módulo" a 'ESNext', me pide que lo haga...
typescript({ module: "ESNext" }),se queja por:
Error: Duplicate regular expression flag (Note that you need plugins to import files that are not JavaScript) src/myCode.ts (512:0) 512: import(MY_JSON_FILE)