Skip to content

Custom webpack config #40

Closed
Closed

Description

@rauchg

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.

Activity

  1. davidrossjones commented on Oct 25, 2016

    @davidrossjones
    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?

  2. TheLarkInn commented on Oct 25, 2016

    @TheLarkInn

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

  3. TheLarkInn commented on Oct 26, 2016

    @TheLarkInn

    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.

  4. DarrylD commented on Oct 27, 2016

    @DarrylD

    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>
    
  5. DarrylD commented on Oct 29, 2016

    @DarrylD

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

  6. ugiacoman commented on Oct 29, 2016

    @ugiacoman

    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?

  7. pksjce commented on Oct 31, 2016

    @pksjce

    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.

  8. ugiacoman commented on Oct 31, 2016

    @ugiacoman

    @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

  9. timoxley commented on Nov 1, 2016

    @timoxley
    Contributor

    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.

  10. vdanchenkov commented on Nov 1, 2016

    @vdanchenkov

    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.

  11. nickjackson commented on Nov 1, 2016

    @nickjackson

    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.

  12. vdanchenkov commented on Nov 1, 2016

    @vdanchenkov

    @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.

  13. timoxley commented on Nov 1, 2016

    @timoxley
    Contributor

    @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.

  14. arunoda commented on Nov 9, 2016

    @arunoda
    Contributor

    @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.

  15. ajhyndman commented on Dec 4, 2016

    @ajhyndman

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

  16. rauchg commented on Dec 4, 2016

    @rauchg
    MemberAuthor

    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)

  17. ajhyndman commented on Dec 4, 2016

    @ajhyndman

    @rauchg Oh, cool. Thanks for the update!

  18. locked as resolved and limited conversation to collaborators on May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions