Babel plugin that transforms dynamic import() calls to also fetch associated CSS chunks via a separate importCss helper. v1.2.1 (2018) was the last release; the project is in maintenance mode. It converts `import('./Foo.js')` into `Promise.all([import('./Foo'), importCss('Foo')])`, automatically generating webpack chunk names via magic comments. Key differentiator: it eliminates manual webpack chunk naming for code-splitting with CSS, integrating with webpack-flush-chunks and universal rendering. Unlike raw CSS-in-JS solutions, it works with standard CSS files.
npm install babel-plugin-dual-importVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: Babel plugin transforms dynamic import to fetch JS + CSS together, using the helper importCss.
Avoid manually adding /* webpackChunkName */ comments; the plugin will override them.
Consider forking or using webpack-native CSS chunk loading (Webpack 5 asset modules).
Upgrade to Babel 7 if using this version.
Ensure __CSS_CHUNKS__ is defined via webpack-flush-chunks or manually in your HTML template.
Use static imports where possible or test chunk naming carefully.
Ensure your webpack config uses ExtractTextPlugin or MiniCssExtractPlugin to emit CSS files.
Run npm install babel-plugin-dual-import and use correct import: import importCss from 'babel-plugin-dual-import/importCss.js'
Use const importCss = require('babel-plugin-dual-import/importCss.js').default;Use plugin as string: "plugins": ["dual-import"]
Install webpack-flush-chunks and configure it per its documentation.