Skip to content

Webpack 2 (3) #169

@kettanaito

Description

@kettanaito

Introduction

Webpack is undoubtedly one of the greatest things to handle JavaScript (any not only) bundling and serving for development and production environments.

Benefits

  • Flexibility. You can configure the source and transformation chain (loaders, plugins) to process your files. Result: Easily adoptable to any project's needs.

  • Performance:

    • Code splitting. Client downloads only that JavaScript code which is really needed at the moment. Result: No redundant downloads, faster page load time.
    • Tree shaking. Automatically analyzes the code and removed unused parts (including 3rd-party libraries). Result: Smaller bundle file size, faster page load time.
    • Varios optimizations (OptmiseJS, Gzip compression, Prepack). Result: More efficient
  • DX:

    • Webpack development server. Provides Hot Module Replacement, which means your changes in JavaScript take place without page reload and loosing the application's state. Result: Faster development process, great DX.
    • Ability to separate vendor bundle (React, Redux, any 3rd-party modules) and client bundle (actual code of the application) and process them separately. Result: Faster initial and incremental builds, faster development process.
    • Simplified build pipeline. With Webpack it is possible to control multiple transformation pipelines of multiples file types (CSS, JS, Images, Fonts, etc.). Result: We can simplify our gulp tasks, remove unnecessary tasks which will be replaced by Webpack, and therefore keep our code cleaner and easier to understand.
  • Extendability. It is possible to easily extend the configuration to bundle CSS, images, fonts, anything. It is also quite simple to create a separate configurations for client/server/vendor/any end-points.

Implementation

This is a rather big change, therefore it is separated into several waves of implementation. Each wave will be followed by pull request and code approval. This issue is regarding only JavaScript bundling as a starting point. We can always extend the configuration once we have it (Webpack can beautifully bundle CSS, images, icons, fonts, anything).

First wave

  • Prepare dev-stack for Webpack
  • Integrate Webpack into our Gulp pipeline
  • Clean up current Gulp tasks which will be gracefully replaced by Webpack (js, lint, etc.)
  • Validate and test optimal configuration setup
  • Provide smart environment-specific configurations/extensions
  • Provide basic loaders for everyday usage
  • (Production) Introduce JavaScript optimization tools (OptimizeJS, prepack, Gzip)
  • Introduce basic set of resolve.alias for utmost DX
  • Introduce vendor.js bundle for third-party libraries (React, redux, younameit)
  • Provide proper lazy initialization of JS modules/components for efficient code splitting

Second wave

  • Document how to configure Webpack
  • Document simplified adjusted workflow
  • Test new configurations on real-scale projects (you can suggest in the comments)
  • Test tree shaking
  • Involve volunteers to test the changes

Third wave

  • Implementing adjustments and suggestions from colleagues
  • Optional code cleaning, configuration performance improvements

Motivation

I would like to use my experience with custom configurations of Webpack from side projects, Conrad, and countless articles and posts on the web. There are a lot of details, which, if not configured, or configured wrong, can cause a spectre of various issues during development and production.

Integration

In order to eliminate incompatibility issues, mentioned changes should be stored in the separate release of gulp-dev-stack repository, marking a new era of our dev-stack.

  • You clone v1 by default
  • You clone v2 when specified

This separation is definitely possible, feel free to suggest how it may be done if you did something similar in your repositories, otherwise I will just read the documentation of Git releases.

Additionally, choosing proper technology for your tasks is a great ground to end up with good implementation. Webpack is a great tool, yet it is still very likely that some projects will not get much benefit from it. This makes versioning even more important than ever.

Update from 23.06

This change has been approved as the part of ACTUM LAB. I will start on this as soon as I align with @DavidSlavik and my PM. Work in progress.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions