Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't minify the output of plugin #45

Open
bAbolfazl opened this issue Oct 6, 2020 · 4 comments
Open

Can't minify the output of plugin #45

bAbolfazl opened this issue Oct 6, 2020 · 4 comments

Comments

@bAbolfazl
Copy link

bAbolfazl commented Oct 6, 2020

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?

@markshapiro
Copy link
Owner

@bAbolfazl did you research why it returns undefined? somebody solved something similar here: #33 (comment)

@andreasnylin
Copy link

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.

@aliechti
Copy link

aliechti commented Dec 1, 2020

@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
},

@andreasnylin
Copy link

@thejahweh Ah yes that's it, thanks! I tried that but places the "async" at the wrong place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants