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

Custom webpack config #40

Closed
rauchg opened this issue Oct 24, 2016 · 18 comments
Closed

Custom webpack config #40

rauchg opened this issue Oct 24, 2016 · 18 comments

Comments

@rauchg
Copy link
Member

rauchg commented Oct 24, 2016

It'd be nice to add hooks for webpack, and describe on the README (similarly to #26) how to for example add require('./something.css') support.

@davidrossjones
Copy link
Contributor

Is this currently unsupported full stop? e.g. there is no way for me to add css-loader to parse .css files via Webpack?

@TheLarkInn
Copy link

You could make a layer that implements Tapable and let people plugin to the instance. :) easy plugin system.

@TheLarkInn
Copy link

Or if anything a hook before build and dev that can return the 'compiler' instance or 'config object' before it calls .run or .watch.

This would provide a single extensible point in which people can explore customize, break, or change the configuration to suit their snowflake applications/workflows.

@DarrylD
Copy link

DarrylD commented Oct 27, 2016

Adding css is pretty important. For the time being, I just leveraged <Head> with cdns or from ./static

Example

<Head>
    <title>My page title</title>
    <link rel="stylesheet" href="/static/css.min.css" />
</Head>

@DarrylD
Copy link

DarrylD commented Oct 29, 2016

would this be considered a webpack issue? wondering if having access to the config could resolve this

@ugiacoman
Copy link

ugiacoman commented Oct 29, 2016

Custom webpack config would be incredible, I'm trying to use react-toolbox but without a SASS loader, I can't do much...

Is there an unofficial way to include a custom webpack config at this point?

@pksjce
Copy link

pksjce commented Oct 31, 2016

IMO, there are two ways of solving this

  • Allow custom webpack.config.js. Something like react-storybook

    Pros - Full control over the application.

    Cons - Right now, next.js gives a lot of functionality out of the box which can be compromised.

  • Have a seperate webpack.next.js in the application code, which allows only a subset of the webpack configs and then adds on to/overrides the current config.

    Pros - We can allow addition of custom loaders/plugins.

    Cons - Does not provide full control over the application since only a subset is allowed. User needs to be educated on what can be customised and what cannot ie need proper warnings and error messages for the same.

@ugiacoman
Copy link

@pksjce Have a seperate webpack.next.js in the application code, which allows only a subset of the webpack configs and then adds on to/overrides the current config.

This solution sounds pretty good

@timoxley
Copy link
Contributor

timoxley commented Nov 1, 2016

A simple option could be to try load user's webpack config, falling back to default config.

User's config would totally overrides the default config, however, the default config would be loadable e.g const nextConfig = require('next/webpack.config')

Then the user could use whatever to extend/mutate this.

e.g.

const nextConfig = require('next/webpack.config')

module.exports = Object.assign({}, nextConfig, {
  devtool: 'eval-source-map'
})

For example, override customise the babel transforms config as needed (#26):

const nextConfig = require('next/webpack.config')

// find babel loader
const babelLoader = nextConfig.module.loaders.find(({loader}) => loader === 'babel')

// mutate to add custom plugin
babelLoader.plugins.unshift('transform-decorators-legacy') // must run first

module.exports = nextConfig

Would also allow users to opt into using something with fancy recursive merging logic like lodash.merge or webpack-config:

const Config = require('webpack-config')

module.exports = new Config().merge(require.resolve('next/webpack.config'), {
  resolve: {
    alias: {
      'immutable': require.resolve('immutable/dist/immutable.min.js')
    }
  }
})

Ideally, this would only need to be used as an escape hatch for emergencies.

@vdanchenkov
Copy link

What do you think about #174 ? Given it's safe to mutate original config and small chances that someone would like to override config completely, I'd not ask end user to return anything from the function. It would be original config object anyway.

@nickjackson
Copy link

I like @timoxley's suggestion above. Object.assign seems like a good way of keeping the config structure familiar, allowing for simple loader/plugin additions, as well as the ability to completely override the default if the user wishes.

@vdanchenkov
Copy link

@nickjackson
Is

return Object.assign({}, nextConfig, {
  devtool: 'eval-source-map'
})

looks more familiar then?

nextConfig.devtool = 'eval-source-map'

I could add return value to API and it would not significantly change suggested usage, but it will make developers think that they have to clone original config while they are not required to do it.

It would make usage too complicated if we require developers to keep original config unchanged.

@timoxley
Copy link
Contributor

timoxley commented Nov 1, 2016

@vdanchenkov using the returned object would allow users to mutate or clone or return an entirely new object. Your current implementation only allows users the option to mutate.

Not sure if this approach is the right avenue or not though.

@pyrossh
Copy link

pyrossh commented Nov 4, 2016

The people at https://github.com/kadirahq/react-storybook have implemented a custom webpack config loader for their app which users can easily add to.

@arunoda
Copy link
Contributor

arunoda commented Nov 9, 2016

@pyros2097 Thanks for the mention. Yep, we allow both webpack and babel and it's working pretty well.

FYI: This is how we do it.

@rauchg, if this is something you'd like to see, I'm happy to work on this.

@ajhyndman
Copy link

Are there any open questions left on this? I really like the idea of the API converging with react-storybook's.

@rauchg
Copy link
Member Author

rauchg commented Dec 4, 2016

Please see #174. It's very possible that we'll admit both a function and an object in the future, but we'll start with the more powerful variant (fn)

@ajhyndman
Copy link

@rauchg Oh, cool. Thanks for the update!

@nkzawa nkzawa closed this as completed Dec 29, 2016
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests