Linaria with preact-cli & preact X
See original GitHub issueDoes anybody have experience with setting up Linaria with Preact-cli/Preact X?
I tried the following: linaria moduleWrapper
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/__mocks__/fileMock.js",
"\\.(css|less|scss)$": "identity-obj-proxy",
"^./style$": "identity-obj-proxy",
"^preact$": "<rootDir>/node_modules/preact/dist/preact.min.js",
"^react$": "preact/compat",
"^react-dom$": "preact/compat",
"^linaria$": "preact/compat",
"^create-react-class$": "preact-compat/lib/create-react-class",
"^react-addons-css-transition-group$": "preact-css-transition-group"
}
.babelrc
{
"env": {
"test": {
"presets": [
["preact-cli/babel", { "modules": false }],
"linaria/babel"
]
}
}
}
preact.config.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
export default {
webpack(config, env, helpers, options) {
// config.resolve.alias = Object.assign({}, config.resolve.alias, {
// react$: 'preact/compat/',
// 'react-dom$': 'preact/compat',
// react: 'preact/compat/',
// 'react-dom': 'preact/compat',
// linaria: 'preact/compat'
// });
config.plugins.push(new MiniCssExtractPlugin({ filename: 'styles.css' }));
config.module.rules.push({
test: /\.m?js$/,
exclude: /(node_modules)/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'linaria/loader'
}
]
});
return config;
}
};
The following error is returned: bundle.esm.js:1593 Error: Using the “styled” tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. Is .babelrc not setup correctly?
Versions: “linaria”: “^1.3.1” “preact”: “^10.0.0-beta.2” “preact-compat”: “^3.17.0” “preact-render-to-string”: “^5.0.3”
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Preact CLI
Preact CLI takes the pain out of starting a new project, getting you up and running instantly with a minimal and understandable project...
Read more >linaria-preact - npm
Fork of Linaria, the blazing fast zero-runtime CSS in JS library, but supporting preact. Latest version: 1.3.2, last published: 3 years ago.
Read more >Ivan Akulov on Twitter: "I've got to admit, I've been doubtful ...
Like, what if I replace React with Preact, and it breaks something? ... Linaria is a 0-runtime alternative with a similar API:.
Read more >preact-cli examples - CodeSandbox
Learn how to use preact-cli by viewing and forking preact-cli example apps on CodeSandbox. ... Preact X + Emotion · developit · Zendesk...
Read more >Next.js | Everything I know - My Knowledge Wiki
Create Next Stack - Opinionated interactive CLI tool to easily set up the ... Next Super Performance - Partial hydration for Next.js with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Tsubasa1218 thank you for the solution 😃 It would be awesome if you could contribute and add a note to linaria documentation about preact configuration!
@secretlifeof
Hello, I think I found a way to make linaria@1.3.3 work with preact@10.3.2
Here is my setup: New app created via:
npx preact-cli create default test
On top of the default template, I installed:
@babel/preset-react
. This is because for linaria to work with JSX syntax, it needs that preset. Otherwise, it will throw an error saying thatlinaria/loader
can’t parse JSX.My
package.json
file looks like the following:Now, create a
.babelrc
file, with the following:The plugins listed here are based on preact’s default template/cli, I just console logged them in
preact.config.js
and moved to the babelrc. I did not add/remove any of the default plugins.Finally, in your
preact.config.js
, the following:For some reason, preact does not like when you push presets/plugins given to it from the preact config file (working with linaria), eg:
I also had to remove the first preset they use:
@babel/preset-typescript
, because I don’t use it. I think that having the first preset (typescript) causes problems. After all that, you should be able to runnpm run build
, it should be green.To test that your build succeded, go to any component file, in my case I picked
components/header/index.js
,I added a linaria generated class name:
Now build, and go to the
build
folder, and look forbundle.[hash].css
, open it in an editor, formate it, and the class you created should be at the bottom.If you run
npm start
, you should be able to see a button next to the nav title, with red bold text.Let me know if this helps you, I struggled two days to make it work x’D