Articles in this section
Category / Section

How do I split the Syncfusion bundles into individual libraries?

3 mins read

When developing React applications with Syncfusion UI components, performance optimization is key. One effective way to enhance performance is by splitting the Syncfusion bundles into individual libraries. This can be achieved using Webpack, and this article will guide you through the process.

Create a React App

Begin by creating a React app following the steps outlined in the Syncfusion documentation for creating a React Webpack app. This typically involves setting up a new React project, installing necessary dependencies, integrating Syncfusion components, and configuring your Webpack settings.

Install the Bundle Analyzer

To visualize the bundles using the bundle analyzer and facilitate splitting, install the Webpack bundle analyzer and the fs module. Run the following npm command in your terminal:

npm i fs webpack-bundle-analyzer --save

Configure Webpack for Splitting Bundles

In the webpack.config.js file, add the following configuration to enable splitting Syncfusion bundles into individual libraries:

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const fs = require('fs');
const syncfusionModules = fs.readdirSync('./node_modules/@syncfusion/');

module.exports = {
    // … other webpack configurations
    optimization: {
        splitChunks: {
            cacheGroups: {
                vendors: {
                    test: /[\\/]node_modules[\\/](?!@syncfusion[\\/])/, // exclude syncfusion packages
                    name: 'vendor',
                    chunks: 'all',
                },
            },
        },
    },
};

syncfusionModules.forEach(moduleName => {
    module.exports.optimization.splitChunks.cacheGroups[moduleName] = {
        test: new RegExp(`[\\\\/]node_modules[\\\\/]@syncfusion[\\\\/]${moduleName}[\\\\/]`),
        name: moduleName, // Use the folder name as the bundle file name
        chunks: 'all',
    };
});

This configuration tells Webpack to use the splitChunks optimization to separate Syncfusion libraries from other vendor libraries. The BundleAnalyzerPlugin can be used to visualize bundle sizes and optimize large dependencies.

Build Bundles

Now run the below command to split the Syncfusion packages.

npm run build

After the build process completes, you can see the Syncfusion bundles split into individual libraries, which can lead to improved load times and overall performance of your React application.

Visualizing the Split Bundles

You can use the BundleAnalyzerPlugin to visualize the split bundles and confirm that the Syncfusion libraries are indeed separated from the main bundle.

bundles

Conclusion

By following the steps outlined above, developers can optimize their React applications by splitting Syncfusion bundles into individual libraries. This can lead to a more efficient and performant application.

Additional References

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied