Coder Social home page Coder Social logo

koba04 / closure-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webpack-contrib/closure-webpack-plugin

0.0 3.0 0.0 726 KB

Webpack Google Closure Compiler and Closure Library plugin -

Home Page: https://developers.google.com/closure/

License: MIT License

JavaScript 100.00%

closure-webpack-plugin's Introduction

closure-webpack-plugin

npm version

This plugin supports the use of Google's Closure Tools with webpack.

Closure-Compiler is a full optimizing compiler and transpiler. It offers unmatched optimizations, provides type checking and can easily target transpilation to different versions of ECMASCRIPT.

Closure-Library is a utility library designed for full compatibility with Closure-Compiler.

Note: This plugin is a very early beta and currently uses a custom build of closure-compiler while necessary changes are integrated back into the main compiler repository. Only the java version of closure-compiler is currently supported.

Usage example

const ClosurePlugin = require('closure-webpack-plugin');

new ClosurePlugin({mode: 'STANDARD'}, {
  // compiler flags here
  //
  // for debuging help, try these:
  //
  // formatting: 'PRETTY_PRINT'
  // debug: true
})

Options

  • mode - STANDARD (default), AGGRESSIVE_BUNDLE or NONE. Controls how the plugin utilizes the compiler.

    • STANDARD mode, closure-compiler is used as a direct replacement for other minifiers as well as most Babel transformations.
    • AGGRESSIVE_BUNDLE mode, the compiler performs additional optimizations of modules to produce a much smaller file, but is not compatible with all input modules.
    • NONE is designed for dev mode without the compiler but still supports closure-library style dependencies.
  • childCompilations - boolean or function. Defaults to false. In order to decrease build times, this plugin by default only operates on the main compilation. Plugins such as extract-text-plugin and html-webpack-plugin run as child compilations and usually do not need transpilation or minification. You can enable this for all child compilations by setting this option to true. For specific control, the option can be set to a function which will be passed a compilation object.
    Example: function(compilation) { return /html-webpack/.test(compilation.name); }.

  • closureLibraryBase - (optional) string. Path to the base.js file in Closure-Library.

  • deps - (optional) string or Array. Closures style dependency mappings. Typically generated by the depswriter.py script included with Closure-Library.

  • extraDeps - (optional) Object. Mapping of namespace to file path for closure-library provided namespaces.

Compiler Flags

The plugin controls several compiler flags. The following flags should not be used in any mode:

  • module_resolution
  • output_wrapper
  • dependency_mode
  • create_source_map
  • module
  • entry_point

Aggressive Bundle Mode

In this mode, the compiler rewrites CommonJS modules and hoists require calls. Some modules are not compatible with this type of rewritting. In particular, hoisting will cause the following code to execute out of order:

const foo = require('foo');
addPolyfillToFoo(foo);
const bar = require('bar');

Aggressive Bundle Mode utilizes a custom runtime in which modules within a chunk file are all included in the same scope. This avoids the cost of small modules.

In Aggressive Bundle Mode, a file can only appear in a single output chunk. Use the Commons Chunk Plugin to split duplicated files into a single output chunk.

Tips for Use

  • Don't use babel - closure-compiler is also a transpiler. If you need features not yet supported by closure-compiler, have babel only target those features.

Maintainers


Chad Killingsworth

Joshua Wiens

closure-webpack-plugin's People

Contributors

chadkillingsworth avatar ferhatelmas avatar fredj avatar hokid avatar joshwiens avatar teppeis avatar tschaub avatar

Watchers

 avatar  avatar  avatar

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.