Skip to content

Overcomplicated @rails/webpacker package? #895

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

Closed
joroshiba opened this issue Oct 4, 2017 · 4 comments
Closed

Overcomplicated @rails/webpacker package? #895

joroshiba opened this issue Oct 4, 2017 · 4 comments

Comments

@joroshiba
Copy link

I love that this just works out of the box, but configuring it after that leaves a lot to be desired.

The basis of the problem being that generally webpack will need some configuration and it is currently 90% extracted out into a node module, and I could start from scratch but it already mostly works.

Maybe I'm missing something, but it seems like you could have a much simpler easy to extend, well documented by webpack configuration with a webpack.base.config.js that is simply extended in dev, test, prod file. Instead it is using a yarn package with and environment class that builds an object and requires me to read the code of the yarn package to change. (The current webpacker documentation here says to look at webpack for configuration information, but that isn't particularly useful IMO when you have built helper libraries to build the config object.)

@renchap
Copy link
Contributor

renchap commented Oct 5, 2017

You can easily add your own Webpack plugins / loaders, see here: https://github.com/rails/webpacker/blob/master/docs/webpack.md
This does not solve the problem to see what the default Webpack config is, but IMO adding your own bits is quite easy.

@joroshiba
Copy link
Author

I looked at this, but it did not allow me to do what I needed to (specifically I need to set the order that loaders are ordered in). I ended removing the package entirely and building my own webpack config.

@gauravtiwari
Copy link
Member

Hey, working on a PR that adds same feature you are looking for - #884

Perhaps, we can also have an eject feature that copies over config files from npm module to your app for customisation.

@gauravtiwari
Copy link
Member

@bytewalls Merged #884 and here is the new API:

// environment.js

environment.loaders.append('json', jsonLoader)
environment.loaders.prepend('json', jsonLoader)
environment.loaders.insert('json', jsonLoader, { after: 'style' } )
environment.loaders.insert('json', jsonLoader, { before: 'babel' } )
// Same API for plugins
environment.plugins.insert('Manifest', /* manifestPlugin instance */, { before: 'ExtractText' } )

// Same for resolved modules
environment.resolvedModules.prepend('vendor', 'vendor')

module.exports = environment

environment.config now returns webpack config object:

// environment.js

const environment = require('@rails/webpacker')

environment.config = // {} webpack config object

environment.config.set('resolve.extensions', ['.foo', '.bar'])
environment.config.set('output.filename', '[name].js')
environment.config.delete('output.chunkFilename')
environment.config.get('resolve')

// Just merge as you would do with webpack-merge
environment.config.merge({ output: {
    filename: '[name].js'
  }
})

module.exports = environment

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

No branches or pull requests

3 participants