Friends, I'm working on an application with ReactJS using es6. I started using browserify for the conversion and compilation of es6 to es5. But I realized that my "bundle" file after the transformation weighs 1.3mb, which is logically too much weight . My src folder with all the scripts in es6 only weighs 200kb . In principle, I thought that browserify was including either all the dependencies (including ones that I did not need) or that I was repeating the files. This is because as you know, in es6 I must use lines like
import Config from .'/config.js';
For the inclusion of files you need and this, in turn I do it in each file. Therefore, I decided to change to webPack because I read that it was in charge of analyzing what it included and precisely avoiding the repetition of code (For me these tools are new). But my compiled file still has a weight of 1.3mb Here I add my dummy file from browserify
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './js/src/index.js',
devtool: 'cheap-module-source-map',
output: { path: __dirname, filename: 'bundle.js' },
"plugins":[
new webpack.optimize.DedupePlugin()
],
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules|libs/,
query: {
presets: ['es2015', 'react']
}
}
]
},
};
With that I generated a map file and there are files that appear multiple times, with which I corroborate that this is the reason why the bundle file weighs so much. Does anyone have any idea how I can solve that?
Regarding the development structure, I am using React and React-router. Therefore, I have an index.js file where I include all the "routes" files to register the routes and then I have a .jsx file for each route, where I import the files I may need.
Update
Reading in documentation, they recommend that the include be used and not the exclude in the loaders. therefore I tried testing in the following way:
module.exports = {
entry: './js/src/index.js',
devtool: 'cheap-module-source-map',
output: {
path: __dirname,
filename: 'bundle.js'
},
"plugins": [
new webpack.optimize.DedupePlugin()
],
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
/* exclude: [
NPM_DIR,
BOWER_DIR
],
*/
query: {
presets: ['es2015', 'react']
},
include: [
path.join(__dirname, 'src/Clases'),
path.join(__dirname, 'src/components'),
path.join(__dirname, 'src/elements')
]
}
]
},
};
But making that adjustment, I get an error as if I did not recognize the presets, throws the following error:
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (129:12)
That line is where the react render method starts, for that the presets are included in the query segment, I had passed before and I solved it like this and now using the key include happens again.
Thank you very much to anyone who can help me because I still do not see light.