-
-
Notifications
You must be signed in to change notification settings - Fork 85
Compatibility with preact #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Alright so for the future visitors, I managed to make this loader compatible with
return {
rules: [
{
test: /\.svg$/,
use: [
// Note the loaders are applied in reverse order!
// 2. Transform JSX to JS.
// Basically copied the existing babel config for JSX files here.
{
loader: 'babel-loader',
options: {
presets: [['env', presetEnvLegacySettings]],
plugins: [
['transform-object-rest-spread', { useBuiltIns: true }],
['transform-react-jsx', { pragma: 'h' }],
]
},
},
// 1. Load SVG and transform it to JSX
{
loader: 'react-svg-loader',
options: {
jsx: true,
},
},
],
},
react-svg-loader/packages/babel-plugin-react-svg/src/index.ts Lines 152 to 155 in fa8b061
- path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier("React"))], t.stringLiteral("react")));
+ path.node.body.unshift(t.importDeclaration([t.importSpecifier(t.identifier("h"), t.identifier("h"))], t.stringLiteral("preact")));
react-svg-loader/packages/react-svg-core/src/index.ts Lines 23 to 25 in fa8b061
- presets: [jsx ? void 0 : "@babel/preset-react"].filter(Boolean),
+ presets: jsx ? [] : [["@babel/preset-react", {pragma: 'h'}]], Another thing I tried but it didn't quite work: without passing but this still requires |
Hello,
I was trying to use the loader with preact (bundling with webpack) and here's what I've found for other interested people.
I used following webpack conf:
Outside of the box, the module does not work with
preact
because of a hard dependency onreact
.When trying to compile the app, there's an error like this:
I managed to fix it by installing
preact-compat
and aliasing it asreact
in webpack config:This works but is not ideal, as
preact-compat
is 13kB (5 kB gzipped) which seems wasteful because the only thing necessary for the module to work isReact.createElement
which should be generally whatpreact.h
does.I will try to find out if there's some way to have a build-time replacement of this instead of runtime dependency on
preact-compat
. If anyone knows how to do it, please let me know.The text was updated successfully, but these errors were encountered: