Coder Social home page Coder Social logo

webpack-5-examples's Introduction

Webpack 5 Examples

What is webpack? https://webpack.js.org

Webpack is a module bundler. It turns source files into deployable web application artifacts.

  • Processes JavaScript and JSON by default.
  • Can be extended to process other file types.
  • Creates a compiler instance which crawls import tree from entry points.
  • Compiler populates a compilation object as it traverses.
  • Provides hooks to give loaders and plugins access to the compiler and compilation object to perform additional, custom operations.
  • Outputs bundles.

Usage of this repo

Examples of various webpack configs, generally increasing in complexity.

For each subdirectory:

  • npm install

For 01-03:

  • ./node_modules/.bin/webpack

For 04-14:

  • npm start

The Examples

01 - Basic

  • Webpack without a configuration file.
  • mode argument (development or production)
  • dist output directory
  • Take a look at the output bundle!
  • Run node dist/main.js for kicks.

02 - Basic With Config

  • Webpack with a simple configuration file.
  • Uses default configuration file name/location

03 - Custom config

  • A mildly customized configuration file, demonstrating some basic settings.
  • Example of how dev/prod configs start to differ
  • Fingerprinting

04 - Environment configs

  • Basic example of having environment-specific (dev, prod) configurations.
  • Common configuration entry point which branches on NODE_ENV.

05 - Common configuration extraction

  • Extracting common configuration elements into a separate file, merged into environment configs.

06 - Webpack Dev Server

  • Usage with webpack-dev-server (very common).
  • Note generated HTML file.
  • Note that bundle is not written to filesystem. It's stored in memory.

07 - Express

  • Running webpack-dev-middleware and webpack-hot-middleware with express
  • Note how hot reloading becomes difficult.
  • Needs a "real" HTML file.

08 - Loaders

  • Using some common loaders for other file types.
  • There are lots of loaders: https://webpack.js.org/loaders/
  • If you didn't realize my love for my cat earlier, you will now.

09 - Plugins

10 - Babel

  • Using babel-loader for JavaScript transpilation.
  • Example of babel preset-env.
  • Note how output changes (const, for instance) if the output target is changed to "ie": "11"

11 - Plugin Authoring

12 - Split Chunks

  • Having multiple entry points and common code extraction.

13 - DLLs

  • Using DLL plugins to extract third party code for faster builds / caching.
  • Note: Example 13 (DLLs) is currently a bit broken. It doesn't properly exclude jquery from the main application bundle.

14 - Code splitting

  • Code splitting with dynamic imports. import()

webpack-5-examples's People

Contributors

davidjoy 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.