0.0.2 • Published 7 years ago

jsx-templates-loader v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

jsx-template-loader

npm

A webpack loader to include JSX files with custom imports.

Install

npm install --save-dev jsx-templates-loader

Usage

Write a JSX file:

<div class="my-component">
	<span>Hello</span>
</div>

Import a JSX file in your js file:

import template from './my-component.jsx';

Config

webpack.config.js

{
	module: {
		rules: [
			{
				enforce: 'pre',
				test: /\.jsx$/,
				loaders: [
					// import your custom hyperscript library at the top of the JSX file
					'jsx-templates-loader?importsHeader="import React from \'react\'"',
				],
			},
			{
				test: /\.jsx$/,
				use: [
					'babel-loader',
				],
			},
		],
	}
}

.babelrc

{
	"plugins": [
		// tell to babel to use your custom hyperscript function using `pragma`
        ["transform-react-jsx", { "pragma": "React" }]
    ]
}