Code Monkey home page Code Monkey logo

webpack-module-nomodule-plugin's Introduction

Webpack module-nomodule plugin

npm version

Installation

npm install --save-dev webpack-module-nomodule-plugin

or

yarn add -D webpack-module-nomodule-plugin

Why

This automates the generation of module-nomodule scripts.

This project relies on html-webpack-plugin.

module-nomodule explained.

How to use

The only thing you need to do is return two build steps in your webpack and forward this to this plugin like this:

  • for legacy new WebpackModuleNomodulePlugin('legacy');
  • for modern new WebpackModuleNomodulePlugin('modern');

The rest will be handled for you!

Output modes

The second argument to WebpackModuleNomodulePlugin allows you to specify an output mode.

At this point there are two:

  • efficient (default)
  • minimal

These are exported as an object containing OUTPUT_MODES.

Efficient

Ensures IE11 and some Edge versions won't double download the contents of your scripts. This adds some more size to your html file and defers the loading of scripts.

This will look something like this:

efficient mode output

What happens in this picture?

  • We declare the modern javascript files as modulepreload to shave a bit off the load/parse time of these
  • We dynamically inject the entry-modules with the bigger script to avoid injecting needlessly

Minimal

Makes the most minimal output possible, this will be downloaded twice on older Edge and IE11.

This will look something like this:

minimal mode output

The script in the middle between type="module" and nomodule is meant for safari 11 compat.

nomodule will load for browsers who don't support module and the other way around, the problem with this approach is we'll be downloading both bundles on certain Edge versions and IE11.

Example

https://github.com/JoviDeCroock/POC-ModularLegacyBuild

This example uses multiple techniques to guarantee the best size, like using native-url in modern browsers, ...

webpack-module-nomodule-plugin's People

Contributors

andieelmes avatar dependabot[bot] avatar ge11ert avatar hydrophobefireman avatar jovidecroock avatar

Watchers

 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.