nativescript-dev-webpack icon indicating copy to clipboard operation
nativescript-dev-webpack copied to clipboard

Ability for Plugins to add to certain settings in webpack config...

Open NathanaelA opened this issue 6 years ago • 4 comments

Is your feature request related to a problem? Please describe. Would be nice if plugins can add/change some of the webpacking configuration ability...

Describe the solution you'd like I would suggest that certain of the fields in the webpack.config file be changeable by some json settings; either as part of the actual plugin package.json file itself; or a hook during install updates the fields in a global application wide webpack json file.

For example: https://github.com/NativeScript/nativescript-dev-webpack/blob/master/templates/webpack.javascript.js#L213

For my sqlite plugin, I would like to add: **.sqlite to the Glob pattern; in addition I would like to add some files to the externals, but the new configuration file appears to be controlled exclusively by environmental variables, which makes it even harder for users to follow my documentation as they need to add two externals for at least one of my plugins. If this could be controlled by plugins, then these externals (& glob patterns) could be "installed" with part of the plugin and the end user wouldn't have to do anything...

Describe alternatives you've considered Rewriting the config file using a hook, to add the missing pieces; but this seems very error prone.

NathanaelA avatar May 10 '19 08:05 NathanaelA

I was thinking about this a bit after seeing #1116 - Can we perhaps create a "config.webpack" inside the root plugin folder that can maybe be a json file;

{ 
    copy: ["someglob", "someglob", "**/*.sqlite"],
    externals: [values, values, values]
   define: {valuex : "blahX", valueY: "blahY"},
   rules: [{some rule}, ...]
}

Off the top of my head, I currently only see these 4 items being changed, and really the most important are the first three -- but we might consider if any other items are needed by any plugins...

Not having this; creates issues for a couple of my plugins where they worked great out of the box in NS < 6. So, if webpack read those in; then the plugins could specify what they need...

Thoughts @DimitarTachev @rosen-vladimirov ???

NathanaelA avatar Feb 12 '20 01:02 NathanaelA

I am actually already doing that in my webpack configs My way is to require another webpack config which is part of an npm package. That way I share it in all my apps. I can share. It could also avoid that annoying overwrite of apps webpack config when the template one has changed

farfromrefug avatar Feb 12 '20 18:02 farfromrefug

@NathanaelA @farfromrefug the common approach to this is using something like webpack-chain (https://github.com/neutrinojs/webpack-chain).

For example Vue cli >3.x has adopted it, so plugins are free to add/modify/remove anything from the configs.

Authoring these plugins is a little cumbersome though...

https://github.com/vuejs/vue-cli/blob/320e3919c9000c5c00be21b30445393b7d4765cc/packages/%40vue/cli-plugin-babel/index.js#L31-L91

rigor789 avatar Apr 28 '20 10:04 rigor789

That is an interesting idea Igor; and maybe that is what needs to happen is that each plugin has a config.js script that webpack loads and they all use the webpack chain so that they can configure things...

NathanaelA avatar Apr 28 '20 13:04 NathanaelA