Skip to content

Make Webpack source code more beginner-friendly #824

@gaearon

Description

@gaearon

I understand this is a very controversial topic and I don't want anyone, especially @sokra, to feel offended. Please feel free to close if you consider my request inappropriate.

I was having a Twitter conversation with @markdalgleish about Webpack, and we both share the view that Webpack's source can be hard to read. (example)

The design is outstanding, and this allows each module to be written as a plugin responding to several compiler events, but on the other hand most of the code is written as nested anonymous functions instead of compiler event handlers, with little outside functions. To outsiders looking to tweak or understand Webpack, myself included, this proves to be a problem, and it's, in my opinion, an unnecessary barrier to adoption and outside contributions.

Personally, I'd find it easier to comprehend if there was little to no nesting in the compiler plugins, and anonymous functions were named and extracted. This would also solve the problem of deep conditions and loops. A potential small upside is improving performance / memory usage by avoiding too much closures. We made a similar refactoring in @babel, so maybe @sebmck can shed some light on whether this helped make codebase easier to maintain and understand.

As a style nit, I'd also consider converting from tabs to spaces (not kidding) to improve Github display. Yes, I do believe it's important and pragmatic issue: Github chooses 8 spaces for displaying tabs, whereas the most widespread JavaScript standard, used by React and a ton other libs, is 2 spaces. This aids in preventing alienation for developers taking a peek at how everything works. IMO it's part of the experience and unless we can persuade Github to make “tab size” a project preference, it's worth doing.

I wonder how much of this is intentional, whether you agree with me—or any feedback really.
Thanks for considering this!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions