webpack-merge-and-include-globally
webpack-merge-and-include-globally copied to clipboard
Can't minify the output of plugin
I have tried to minify the output of this plugin as it said in transform section of documentation:
files: { 'vendor.js': [...] }, transform: { 'vendor.js': code => require("uglify-js").minify(code).code }
But I have faced this error:
throw new ERR_INVALID_ARG_TYPE( TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
Could you give me a way to do the modification on the output of this plugin with other plugins such as Terser?
@bAbolfazl did you research why it returns undefined? somebody solved something similar here: https://github.com/markshapiro/webpack-merge-and-include-globally/issues/33#issuecomment-601142507
I have the same problem. I get this error message:
[webpack-cli] TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined at Function.from (buffer.js:207:11) at getContent (C:\Repositories\MetamatrixWebsite\Website2016\Metamatrix.Web\node_modules\webpack\lib\Compiler.js:578:24) at processExistingFile (C:\Repositories\MetamatrixWebsite\Website2016\Metamatrix.Web\node_modules\webpack\lib\Compiler.js:647:24) at outputFileSystem.stat (C:\Repositories\MetamatrixWebsite\Website2016\Metamatrix.Web\node_modules\webpack\lib\Compiler.js:709:10) at callback (C:\Repositories\MetamatrixWebsite\Website2016\Metamatrix.Web\node_modules\graceful-fs\polyfills.js:295:20) at FSReqWrap.oncomplete (fs.js:154:5)
When I try to do this:
transform: { 'scripts/footer.js': code => require("terser").minify(code).code }
If I do a console.log of require("terser").minify(code) I get:
Promise { { code: '/*! jQuery v3.4.1 | (c) JS Foundation and other contributors ... .addClass("d-none"))}));' } }
But if I console.log require("terser").minify(code).code it says undefined.
@andreasnylin This is because Terser.minify returns a Promise. You can do it like this:
transform: {
'filename.js': async (code) => (await Terser.minify(code)).code
},
@thejahweh Ah yes that's it, thanks! I tried that but places the "async" at the wrong place.