Jade to React JS loader for Webpack
PreRequisites
- React & Webpack are peerDependencies (will be installed automatically with npm 2 but left to end-user under npm 3)
Usage
Like any loader can be set up in a configuration file but to use in a require statement:
var React = ; var template = ; var JadeComponent = React;
Passing Arguments to templates
- If
locals
is an object specifying the components props you can then render the template on the page like so:
React;
- OR by passing options through the loader
var React = ; // pass options as jsonvar template = ; var JadeComponent = React;
- OR by passing arguments directly to the template function
- For example if you are using the
css-loader
(andstyle-loader
) to create modular CSS packages- typical webpack config:
module: loaders: test: /\.css$/ loader: 'style!css?modules&localIdentName=[name]__[local]___[hash:base64:5]'
- then you could pass these styles to your jade template like so:
var React = ;var styles = ; var template = ; var JadeComponent = React;
- where they could be referenced as class names:
section(className=styles.content) h1 Hey There!
More Info
-
A simple example app (using ES6 syntax) can be seen at jade-react-loader-example
-
Loader uses the react-jade package and Jade templates are subject to the same limitations as listed there.
Acknowledgements
- Thanks to kilokeith for valuable contributions