markshapiro / webpack-merge-and-include-globally

Merge multiple files (js, css..) and include by running them "as is". Supports minify by custom transform and wildcard paths.
MIT License
102 stars 27 forks source link

Symfony Encore – minify using Terser #33

Open jremen opened 4 years ago

jremen commented 4 years ago

Hello, I'm trying to use this plugin with webpack encore. I can concate JS files with encore webpack config like this:

const MergeIntoSingleFilePlugin = require('webpack-merge-and-include-globally'); .addPlugin( new MergeIntoSingleFilePlugin({ files: {} })

But I'm not able to use transform function with Terser plugin like: tranform: { 'myfile.js': code => new TerserPlugin({include: 'myfile.js.js'}).minify(code).code }

It seems like terser will not notify that my file exists at all or is running before concatenation is finished. File is concatenated just fine, but minification doesn't work.

Also, I'm aware that Terser is already part of Encore and I don't want to call it like that, but this is probably questions for encore developers.

jremen commented 4 years ago

nevermind, solved: transform: { 'myfile.js': function(fileContent, path) { return uglifyJsContents.minify(fileContent.toString()).code.toString() } }