speedskater/babel-plugin-rewire

Webpack bundle size increases dramatically with rewire

Opened this issue · 1 comments

I installed babel-plugin-rewire modules to my project.
npm install babel-plugin-rewire
And config the .babelrc plugin with
"plugins": ["transform-object-rest-spread", "rewire"]

Now when I build the project, I see that the webpack bundle is increased dramatically (almost 2 MB)
From
app.js 6.49 MB 0 [emitted] [big] app
To
app.js 8.33 MB 0 [emitted] [big] app

Is this expected? Is there a way that I can use rewire so that I can test my private unit test and remove it from the webpack bundle?

You should probably use .babelrc.js and provide conditional config:

module.exports = api => ({
    // ...
    plugins: [
        ...api.env('test') ? ['babel-plugin-rewire'] : []
    ]
});

This way rewire should only run when you run tests. Also check if env variable is set to test if your test runner doesn't do it for you already.