Install
Immutable styles can be integrated with Webpack using the Webpack plugin.
🔮 Support for other build systems (such as Parcel) will be added in future releases.
The first step is to install the dependency immutable-styles
:
Next, since immutable styles uses JSX the following devDependencies are required:
Note on devDependenciesIt would be reasonable to assume the packages
@babel/plugin-transform-react-jsx
and@babel/plugin-transform-react-jsx-source
indicate that immutable styles is coupled to React. Don't let the package names fool you! These packages enable immutable styles to use JSX and nothing more. Immutable styles is markup agnostic – meaning it isn’t coupled or biased to a specific way of generating HTML.
Configure Plugin
In webpack.config.js
add the ImmutableStylesWebpackPlugin
:
Then enable source-maps and set nodes fs
module to empty:
Note on Source MapsSource maps are required for compile-time errors. If source maps are not enabled the error
Missing Source Maps
will be thrown.
By default the CSS generated by immutable styles is located in dist/bundle.css
. This can be optionally configured when initialising the plugin:
Then make sure the immutable style sheets are passed through babel-loader
:
And lastly in .babelrc
register the following presets and plugins:
Examples
Some examples of using immutable styles with Webpack can be found in the following repos:
immutable-styles-html-example: which shows how to use immutable styles with plain HTML
immutable-styles-react-example: which shows how to use immutable styles with React
Last updated