Coder Social home page Coder Social logo

Comments (5)

alexander-akait avatar alexander-akait commented on May 2, 2024 1

@michael-ciniawsky if you have ideas - welcome to slack, this repo not for discussion about implementation minimizer features in webpack.

from management.

michael-ciniawsky avatar michael-ciniawsky commented on May 2, 2024

This effort ideally takes the interface introduced with webpack >= v4.0.0 into account (optimization.minimize) and removes the need for optimization.mimimizer as an alternative way to add multiple minimizer plugins (which is the same as adding multiple plugins via config.plugins atm 🤷‍♂️). A webpack wrapper (minimze|optimization)-webpack-plugin based on the uglifyjs-webpack-plugin code should be sufficient and easier to use and maintain

webpack.config.js

const config = {
   optimization: {
      // Defaults for '.js', '.css', '.html', maybe based on mode (recommended)
      minimize: true || false // {Boolean}
      // 'Advanced' (Interface)
      minimize: {
        '.js': '{Boolean}' || { /* Babel Minify Options */ } || '{Function}' // (e.g terser)
        '.css': '{Boolean}' || { /* CSSNano Options */ } || '{Function}' // (e.g csso)
        '.html': '{Boolean}' || { /* HTMLNano Options */ } || '{Function}' // (e.g html-minifier)
      },
      // Custom Minimizer {Function}
      minimize : {
        // Override/Register a custom minimizer { 'extname': workerFn }
        '.ext': (asset, options, cb) => {}
      }
   }
}

from management.

alexander-akait avatar alexander-akait commented on May 2, 2024

@michael-ciniawsky i don't think it is good idea use this:

      minimize: {
        '.js': '{Boolean}' || { /* Babel Minify Options */ } || '{Function}' // (e.g terser)
        '.css': '{Boolean}' || { /* CSSNano Options */ } || '{Function}' // (e.g csso)
        '.html': '{Boolean}' || { /* HTMLNano Options */ } || '{Function}' // (e.g html-minifier)
      },
      // Custom Minimizer {Function}
      minimize : {
        // Override/Register a custom minimizer { 'extname': workerFn }
        '.ext': (asset, options, cb) => {}
      }

It is require webpack have cssnano/htmlnano/etc in deps (because each plugin have minificator in deps). Also webpack doesn't support css/html by default. It's better to let people choose which plugin they want.

from management.

michael-ciniawsky avatar michael-ciniawsky commented on May 2, 2024

Sure, using separate plugins for each asset type is an equal alternative, but then the optimization.* options are more confusing then just using config.plugins directly instead imho (in terms of API design, e.g see the mini-css-extract-plugin README). An abstraction/wrapper could also ship without .css/.html support by default and one has to register minifiers for these

The worker of a potential wrapper plugin could still support different assets types by extension, instead of having to redundantly code this for each and every minifier plugin

worker.js

function worker (asset, options, cb) {
   const type = path.extname(asset.url)

   switch (type) {
     ...js

     case '.css': 
       options[type](asset, options, cb)
          
       break

    ...
  }
}

But on the other hand maybe it's better solved with some kind of plugin-utils providing this functionality (workers, cache) for plugins in general instead idk...

from management.

michael-ciniawsky avatar michael-ciniawsky commented on May 2, 2024

Yep Yep sry :)

from management.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.