Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat(webpack-config): implement pass webpack config path #894

Conversation

soarer1004
Copy link

@soarer1004 soarer1004 commented May 16, 2019

PR Checklist

What is the current behavior?

Currently webpack.config.js is hardcoded in projectFilesManager.js:60. There is no way to specify webpack config path/name.

What is the new behavior?

Now there is way to specify webpack config path/name in nsconfig.json, for example:

{
    "webpackConfig": "webpack/config.js"
}

Implements #654.

@cla-bot cla-bot bot added the cla: yes label May 16, 2019
@ghost ghost added the new PR label May 16, 2019
@KristianDD
Copy link
Contributor

KristianDD commented May 29, 2019

Hi @soarer1004 ,
Thank you for the great contribution and excuse us for the late response. We have concentrated our efforts on preparing the NativeScript 6.0 release and are a bit behind on contribution PR reviews.

In 6.0 (and probably shortly after that) there will be major change in the nativescript-dev-webpack code base, that will affect the feature that you have suggested. We will consider integrating this solution or a similar one that solves the same problems/use cases in some of the post 6.0 releases. In order to have better understanding of the feature, could you please elaborate a bit more on how you are planning to use it and what problems it solves in your development process?

@edusperoni
Copy link
Contributor

@KristianDD I was just about to submit a similar PR, albeit simpler (just exposing env.webpackConfig https://github.com/edusperoni/nativescript-dev-webpack/tree/custom-config), so I'll chime in.

Usually when developing with webpack we have the choice to extend the default config or create multiple environments, like webpack.config.shared.js, webpack.config.dev.js and webpack.config.prod.js. This is a greater issue in {N} because the config is overwritten at every nativescript-dev-webpack update, so we have to reapply every change again.

Since everything is in webpack.config.js, running a diff to find what we should reapply is a bit harder since our custom code is mixed in it. By allowing custom config files, we can do this:

// webpack.config.prod.js
const originalConfig = require("./webpack.config");

module.exports = env => {
    env.uglify = true;
    const config = originalConfig(env);
    config.plugins.push(new MyPlugin());
    return config;
};

So it would be useful to be able to specify the config at build time. I'm also against allowing to change it only in nsconfig.json for the reasons I already stated.

@rosen-vladimirov
Copy link
Contributor

Thanks @soarer1004 , your input is really valuable for us. We'll keep this PR open and we'll take all your input when designing the way we'll improve the flexibility of using different and custom webpack.config.js files.

@manzapanza
Copy link

manzapanza commented Sep 2, 2019

Same problem here. I would like to specify the name of the webpack file only for improve the organization of the config. files of the project and to maintain the same naming convention *.tns.js for NativeScript specific files. I have a shared project with Angular and Nativescript.. and by default Angular has a webpack builtin config (without a specific file in the project) and for NativeScript is named webpack.config.js. But now I need add a partial webpack file for Angular to setup videojs-record (as described here) using ngx-build-plus and I would like use webpack.config.js for Angular and webpack.config.tns.js for NativeScript.

@halfnelson
Copy link

I would love something like this for Svelte Native. Currently every nativescript update clobbers the webpack changes and I need to re-add the svelte-loader. It also prevents me from having svelte native usable as a --template parameter to tns create. If not this solution, one that lets you add plugins to a different config file, (like nsconfig.js) would suffice

@rosen-vladimirov
Copy link
Contributor

Hey @soarer1004 ,
Thank you for this PR. We've applied a lot of changes since then, so this PR is no longer applicable for this repository. Currently NativeScript CLI is the one, which starts the webpack process, so based on your idea, I've managed to create a PR there: NativeScript/nativescript-cli#5216

I'm closing this PR, but thanks for your time and effort!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants