To use webpack code-splitting in formol, you will have to do these modifications to your webpack.config:
module: { rules: [ { test: /\.(mjs|jsx?)$/, exclude: /node_modules\/(?!(formol)\/).*/, // <- this line allows formol use: { // to be built alongside loader: 'babel-loader', // your project }, options: { presets: [ '@babel/preset-react', [ '@babel/preset-env', { targets: { browsers: 'last 1 version and > 3%' }, modules: false, }, ], ], plugins: [ // <- these plugins are needed to build formol '@babel/plugin-syntax-dynamic-import', ['@babel/plugin-proposal-decorators', { legacy: true }], 'add-react-static-displayname', ['@babel/plugin-proposal-class-properties', { loose: true }], ], }, }, ],},resolve: { // <- these extensions needed to be loaded by webpack extensions: ['.mjs', '.js', '.jsx'],},
NB: It is also possible to use the prebuilt version of formol, in this case you will have to copy the javascript files in node_modules/formol/lib in your output.path instead of modifying your webpack config.
Now you are all set.
But before going too deep, let’s take a look at the two following exemples: