-
Notifications
You must be signed in to change notification settings - Fork 213
Feature request: command to output final webpack config #96
Comments
I had some similar issues and found it helpful to output the config object. You can do this by adding adding a custom neutrino config like so:
And adding that to the presets (as the last one) It's not ideal, and a flag on neutrino is cleaner, but it may unblock you. |
dumping the config after each modification would be cool. I haven't used it enough yet to judge if it would be better, but doing |
As far as debugging a preset, I usually use module.exports = neutrino => {
console.log(neutrino.getWebpackOptions());
}; I think having a const alpha = ({ config }) => config.entry('index').add('src/index.js');
const beta = ({ config }) => config.entry('index').prepend('babel-polyfill');
const gamma = ({ config }) => config.entry('index').add('webpack/hot/dev-server');
// Neutrino v5.alpha .use()
neutrino.use(alpha);
neutrino.use(beta);
neutrino.use(gamma); (Maybe a diff like this would be useful?) # ––– neutrino.use
- {}
+ {
+ entry: {
+ index: [
+ "src/index.js"
+ ]
+ }
+ }
# ––– neutrino.use
{
entry: {
index: [
+ "babel-polyfill",
"src/index.js"
]
}
}
# ––– neutrino.use
{
entry: {
index: [
"babel-polyfill",
"src/index.js",
+ "webpack/hot/dev-server
]
}
} |
+1 to having a debug/verbose mode which could just show snapshots of before and after applying middlewares. Even better I think would be showing diffs nicely formatted to reduce noise. What do you think @eliperelman of adding that to the |
hahahahah wow. Love it :-) |
@SpencerCDixon OMG wow |
So one thing to think about: if I'm trying to debug I probably don't want to see a dif between EVERY preset. But I might want to be able to see the changes between 2 or 3. If possible to use something a tad more advanced than just |
@SpencerCDixon I think we can iterate on it later. Maybe |
@eliperelman I like the idea of a coloured diff, although that could easily be generated by existing diff tools as simply as: neutrino build --debug --presets a,b > before.json
neutrino build --debug --presets a,b,c > after.json
favorite-diff-tool before.json after.json At a minimum, let's output the result of I think the most important change to make is cultural. Get people - especially newcomers - into the habit of printing the webpack config to see the effects of the presets and options they're enabling, so that |
@wmadden you're totally right on the diffs, this should be handled externally. I had a local implementation working that I just wasn't happy with, so I'm glad you raised this. Regarding echoing the JSON to stdout, I just need to make sure that there aren't any console.logs that will intermingle with the data, and this should be easy enough. I also think a more appropriate flag is needed, maybe |
I just realized that we can't spit out JSON, since Webpack configs are code, not necessarily all data. Gonna need to think this through a little more. |
In order for this to be solved, we have to avoid conflating two things which we are currently doing:
They may seem the same, but the problem lies in that you cannot just echo a Webpack configuration and have it work, since it relies on the scope and context of its creation. So to require a Webpack configuration, you can use the API (proposed v5 syntax): const Neutrino = require('neutrino');
const api = new Neutrino();
api.use(alpha);
api.use(beta);
api.use(gamma);
// or alternatively by pulling from package.json
require('./package.json').neutrino.presets.map(preset => api.use(preset));
module.exports = api.getWebpackOptions(); Getting a string of the Webpack options is possible from the CLI, but then is not consumable by Webpack. |
Fair enough. I think it'd be worthwhile giving people a way to view a representation of the webpack options, even if it's not usable as an input to webpack. |
@wmadden agreed, I'm working on it as we speak. Probably under |
Resolved with #86. |
Sorry to resurrect an oldie… In debugging / sanity checks, I've too have found myself wanting a dump of the working webpack config - mostly to determine if I'm dealing with a webpack issue or a neutrino one.
@eliperelman I'm sure this is correct, but can you elaborate, or provide an example? Just trying to wrap my head around it. Are you saying an working config output is impossible to generate? So, I started with something like
…and quickly realized bits like this were going to be a problem:
Ultimately I was looking for something like |
I did something like this:
|
I still think this in tricky territory that we just don't have the resources to support. In order to generate a working webpack.config.js from ejection, that means needing to dump into package.json, and get a bunch of references right, as well a string-building a config. It's entirely possible to dump the config currently, either using |
I strongly feel However that's a dupe of #328, which really needs changes in webpack-chain first (which is neutrinojs/webpack-chain#25). I experimented locally with a few approaches to try and improve the situation, but they were all kind of hacky and I reached my yak shaving allowance for the month before I had time to come up with something better. |
Agreed. |
This take advantage of the new webpack-chain `toString()` added in neutrinojs/webpack-chain#53. The output from `neutrino --inspect` now lists the correct plugin declarations and arguments, annotates plugins/loaders with hints about how to reference them in a custom Neutrino config, and supports using `__expression` to override the stringified output when needed. The usage of `deep-sort-object` has been removed since it breaks the new `toString()` comment annotations, and really if sorted output is considered important, it should be handled by webpack-chain itself. Fixes #328. Refs #96.
v8.3.0 has just been released, which backports the upcoming Neutrino 9's improved |
The command didn't help me for other configurations besides webpack, namely the configuration-builder for To others looking for an general way to eject from any const neutrino = require("neutrino")
const Config = require('webpack-chain');
console.log(Config.toString(neutrino().webpack(), { verbose: true }));
console.log(Config.toString(neutrino().jest(), { verbose: true }));
// etc. |
I recently started a project to try out Neutrino and while the initial setup was pretty easy, as soon as I wanted to make a change to the (eventual) webpack configuration I struggled to work out how to do it.
My first attempt to understand exactly what was ending up in webpack was to try to get ahold of the configuration object that webpack would receive. I was surprised to find there was no way to make
neutrino
output it, either using a--verbose
flag or with a separate command. In the end I just added a custom preset which would print it out.One of the biggest problems I observed using Grunt in production is that plugins you'd add would each modify the grunt configuration object, so that the actual configuration of tasks that'd be run would pass through many (often invisible) intermediate states before being used, making debugging impossible. I see a similarity here, in that after applying a couple of presets I had no way to know what webpack configuration was actually being used.
I think it'd be a good idea to make the underlying configuration more transparent to users - give them a way to see what it is before and after applying presets, and with different config properties switched on/off, and encourage them to use it in the documentation.
Moreover it'd give people a way to "eject" from Neutrino (borrowing the terminology from
create-react-app
), should they need to.The text was updated successfully, but these errors were encountered: