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

Minify Options #162

Merged
merged 1 commit into from Nov 22, 2016
Merged

Minify Options #162

merged 1 commit into from Nov 22, 2016

Conversation

boopathi
Copy link
Member

@boopathi boopathi commented Sep 19, 2016

Each option corresponds to and enables/disables a plugin if the value is truthy. If the value is an object, it passes the object as the plugin options. The test snapshot file explains about the possibilities.

Options Manager spec:
/**
 * Options Manager
 *
 * Input Options: Object
 * Output: Array of plugins enabled with their options
 *
 * Handles multiple types of input option keys
 *
 * 1. boolean and object values
 * { mangle: true } // should enable mangler
 * { mangle: { blacklist: ["foo"] } } // should enabled mangler
 *                                    // and pass obj to mangle plugin
 *
 * 2. group
 * { unsafe: true } // should enable all plugins under unsafe
 * { unsafe: { flip: false } } // should disable flip-comparisons plugin
 *                             // and other plugins should take their defaults
 * { unsafe: { simplify: {multipass: true}}} // should pass obj to simplify
 *                                           // other plugins take defaults
 *
 * 3. same option passed on to multiple plugins
 * { keepFnames: false } // should be passed on to mangle & dce
 *                       // without disturbing their own options
 */

Options:
[
      optionsMap.evaluate,
      optionsMap.deadcode,

      group("unsafe", [
        optionsMap.flipComparisons,
        optionsMap.simplifyComparisons,
        optionsMap.guards,
        optionsMap.typeConstructors,
      ]),

      optionsMap.infinity,
      optionsMap.mangle,
      optionsMap.numericLiterals,
      optionsMap.replace,
      optionsMap.simplify,

      group("properties", [
        optionsMap.memberExpressions,
        optionsMap.propertyLiterals,
      ]),

      optionsMap.mergeVars,
      optionsMap.booleans,
      optionsMap.undefinedToVoid,
      optionsMap.regexpConstructors,

      optionsMap.removeConsole,
      optionsMap.removeDebugger,
      optionsMap.removeUndefined,

      proxy("keepFnName", [
        optionsMap.mangle,
        optionsMap.deadcode
      ])
]

Defaults
const PLUGINS = [
  ["evaluate",            require("babel-plugin-minify-constant-folding"),                 true],
  ["deadcode",            require("babel-plugin-minify-dead-code-elimination"),            true],
  ["flipComparisons",     require("babel-plugin-minify-flip-comparisons"),                 true],
  ["guards",              require("babel-plugin-minify-guarded-expressions"),              true],
  ["infinity",            require("babel-plugin-minify-infinity"),                         true],
  ["mangle",              require("babel-plugin-minify-mangle-names"),                     true],
  ["numericLiterals",     require("babel-plugin-minify-numeric-literals"),                 true],
  ["replace",             require("babel-plugin-minify-replace"),                          true],
  ["simplify",            require("babel-plugin-minify-simplify"),                         true],
  ["typeConstructors",    require("babel-plugin-minify-type-constructors"),                true],
  ["memberExpressions",   require("babel-plugin-transform-member-expression-literals"),    true],
  ["mergeVars",           require("babel-plugin-transform-merge-sibling-variables"),       true],
  ["booleans",            require("babel-plugin-transform-minify-booleans"),               true],
  ["propertyLiterals",    require("babel-plugin-transform-property-literals"),             true],
  ["regexpConstructors",  require("babel-plugin-transform-regexp-constructors"),           true],
  ["removeConsole",       require("babel-plugin-transform-remove-console"),                false],
  ["removeDebugger",      require("babel-plugin-transform-remove-debugger"),               false],
  ["removeUndefined",     require("babel-plugin-transform-remove-undefined"),              true],
  ["simplifyComparisons", require("babel-plugin-transform-simplify-comparison-operators"), true],
  ["undefinedToVoid",     require("babel-plugin-transform-undefined-to-void"),             true],
];

@kangax
Copy link
Member

kangax commented Nov 3, 2016

@boopathi could you rebase this?

@boopathi
Copy link
Member Author

boopathi commented Nov 3, 2016

Missed regexp-constructors. will add that.

+ (Close #54)

Extract OptionsManager to a separate file

Update keepFnName and snapshots

Add regexp constructors

rewrite options manager

Fix lint

Remove deadcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tag: New Feature Pull Request adding a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants