I'm trying to do a JS compiler in Node for websites, but I'm hitting a snag.
My compiles keep imports set in the JS. So when its read by the browser it says Uncaught SyntaxError: Cannot use import statement outside a module
My old compiling solution seems to, when hitting an import in the JS code, to simply go get that file and import its contents in the minified version. My new one just copies the import straight in the minified file.
I'm trying to compile with terser, tried a few options, but found none that did what I'm talking about. Is there one I missed, or am I supposed to do those imports another way?
Here is a sample of my current code:
import minify from '@node-minify/core';
import compressorJS from '@node-minify/terser';
function compileJS(el,filename){
if(noisy){console.log('\x1b[31mFCN compileJS ('+el+')\x1b[0m');}
if(!el.includes('.min.')){
minify({
compressor:compressorJS,
type:'js',
input:el,
output:path.resolve(__dirname+'/../../',outPutRouting(el.replace('.js','.min.js'))),
options:{
ecma : 2015,
sourceMap: true,
mangle:false,
compress:{
},
},
callback: function(err, min) {
//console.log('minified')
if(err){
console.log('\x1b[33mBug dans '+el);
console.log(err);
console.log('\x1b[0m');
}
uploadFile(el);
return;
}
})
}
}
And here is the kind of code I'm trying to do an import in, and its just straight giving me the import instead of brigning its contents in the compiled file.
I also tried the same compile with uglify-js and it didnt work. https://www.npmjs.com/package/node-minify
