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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle custom webpack config #312

Merged
merged 5 commits into from
Mar 22, 2020

Conversation

Idered
Copy link
Contributor

@Idered Idered commented Mar 21, 2020

It add support for web/config/webpack.config.js file.

Two formats are supported:

module.exports = (config, {env}) => {
  if (env === 'development') {
    // Add dev plugin
  }
  config.module.rules.push({...})

  return config
}

⬆️ user can use this format to overwrite base config or return completely new config.


module.exports = {
  module: {
    rules: [{...}]
  }
}

⬆️ this format will merge with base webpack config.

TailwindCSS support can be added with:

const configDir = __dirname

module.exports = (config) => {
  config.module.rules[0].oneOf[5] = {
    test: /\.css$/,
    sideEffects: true,
    use: [
      'style-loader',
      { loader: 'css-loader', options: { importLoaders: 1 } },
      {
        loader: 'postcss-loader',
        options: {
          config: {
            path: configDir,
          },
        },
      },
    ],
  }

  return config
}

I guess that postcss should be supported by default - CRA and NextJS does support it.

closes #309

Copy link
Contributor

@peterp peterp left a comment

Choose a reason for hiding this comment

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

Thanks so much for this!

I've left some feedback on this.

I definitely prefer having a single approach for mutating the configs, and the merge approach makes the most sense.

I think if people are at the point where they need to return a completely new webpack config that they're likely better off not using yarn rw dev web, and instead runningyarn webpack --config <path/to/config> themselves.

packages/internal/src/paths.ts Outdated Show resolved Hide resolved
packages/core/config/utils.js Outdated Show resolved Hide resolved
packages/core/config/utils.js Outdated Show resolved Hide resolved
@peterp peterp merged commit 8230dc5 into redwoodjs:master Mar 22, 2020
@thedavidprice
Copy link
Contributor

Hi gents. This looks fantastic! And now we definitely need some docs 😉

Opening an issue linking here for the meantime.

mohsen1 pushed a commit to mohsen1/redwood that referenced this pull request Apr 12, 2020
@thedavidprice thedavidprice added this to the unassigned-version milestone May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customize webpack config
3 participants