Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add preset configuration support to webpack #17171

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

burhanuday
Copy link
Member

@burhanuday burhanuday commented May 10, 2023

Summary

Motivation:
Currently, setting up Webpack configurations can be a time-consuming process, especially for new users. By introducing preset support, we aim to simplify this process and provide a more streamlined experience. Users can select a preset that aligns with their project requirements, reducing the need to write complex configurations from scratch.

This PR introduces a new feature to Webpack, allowing users to add presets as their configuration. A preset is a base configuration that can be extended from, providing a convenient way for users to set up their projects quickly and efficiently.

馃 Generated by Copilot at 15be2ad

This pull request adds a new feature to support Presets in webpack configuration. Presets are arrays of predefined options that can be applied to the whole configuration or to individual configurations in an array. The pull request introduces a new class PresetProcessor that uses the webpack-merge module to merge the preset configurations into the webpack options object. It also updates the lib/webpack.js, schemas/WebpackOptions.json, lib/config/normalization.js, .eslintignore, package.json, and package-lock.json files to enable and support the new feature.

Details

The syntax i am working towards is:

module.exports = {
  presets: WebpackOptions[]
  // Other configuration options...
};

so that the usage looks something like this

// non existent packages
const react = require("react-preset-webpack");
const tailwind = require("tailwind-preset-webpack");

module.exports = {
  presets: [react(), tailwind()]
  // Other configuration options...
};

This opens up the possibility to pass an options object to the plugin

// non existent packages
const tailwind = require("tailwind-preset-webpack");

module.exports = {
  presets: [tailwind({
    config: "./tailwind.config.js"
  })]
  // Other configuration options...
};

馃 Generated by Copilot at 15be2ad

  • Add support for presets in webpack configuration (link, link, link, link, link)
  • Exclude .mjs files from linting process (link)
  • Add webpack-merge dependency to package.json (link)

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@burhanuday burhanuday changed the title feat: add preset configuration support to webpack [WIP] feat: add preset configuration support to webpack May 10, 2023
@burhanuday burhanuday changed the title [WIP] feat: add preset configuration support to webpack feat: add preset configuration support to webpack May 15, 2023
@burhanuday burhanuday marked this pull request as ready for review May 15, 2023 14:59
@burhanuday
Copy link
Member Author

@alexander-akait @TheLarkInn @snitin315 let me know your thoughts on this. if this is not the approach we want to take, i'll drop this

Copy link
Member

@TheLarkInn TheLarkInn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burhanuday there's one scenario that I recall @patak-dev called out to me when discussing this feature. I believe that Rollup/Vite has the ability to have -plugin's be a collection of applied plugins.

What I would like to see is a adding a test case that covers a variety of scenarios where:

  • One preset adds transitively multiple presets
  • Preset A => Preset B => Preset C
  • Potentially mitigating some merge cases (but maybe thats a webpack-merge scenario) or custom logic in the Processor

@burhanuday
Copy link
Member Author

@TheLarkInn added a complex working example with the situation you mentioned above

The webpack.config.js has two presets simple and react. The simple preset depends on preset css

webpack.config.js 
        => simple
              => css
        => react

@burhanuday
Copy link
Member Author

Opened a PR in webpack-merge to deep merge loader options - survivejs/webpack-merge#206

@burhanuday
Copy link
Member Author

The webpack-merge PR has been merged. It means that options will now be deep merged. This approach is viable 馃帀

@burhanuday
Copy link
Member Author

@TheLarkInn friendly ping here

@TheLarkInn
Copy link
Member

Let's rebase @burhanuday and this is going through review here this week. Appreciate the patience and work on this. 馃憦

@webpack-bot
Copy link
Contributor

@ Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@TheLarkInn Please review the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants