I have a file where I'm exporting multiple consts with arrays of children called icons.js.
In another react file, lets call it CloseButton.js. I'm only importing
import { cross } from './icons.js';
and when I run webpack with production mode enabled, all the other icons appear to be imported as well (the icons.js const exports amount to close to 100kB or so, but a single line shouldnt be larger than 1kB) to the transpiled CloseButton.js.
I am using webpack 4.30.0 with @babel/preset-env and @babel/preset-react.
webpack.config.js
const config = {
entry: './CloseButton.js',
output: {
filename: 'CloseButton.js',
},
plugins: [],
module: {
rules: [
{
test: /\.js/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
modules: false
}], '@babel/preset-react']
}
}
}
]
},
mode: 'production'
};
module.exports = config;
I tested to run the same setup but only exports strings from icons.js
, and then the code was properly excluding dead code.
Does anybody know if there's a way to only export "cross" from the icons.js file without creating a separate file for each react component defined in icons.js?
I've tested removing all references of const
s being exported as React components from icons.js and that works, but that doesn't let me export the icons.