@calmery-chan/aleph-plugin-emotion
v2.0.0
Published
A plugin for using :woman_singer: with Aleph.js
Downloads
4
Readme
@calmery-chan/aleph-plugin-emotion
A plugin for using :woman_singer: with Aleph.js.
Features
Can only use @emotion/css.
- [x] API
- [x] Generate Class Names —
css
- [x] Global Styles —
injectGlobal
- [x] Animation Keyframes —
keyframes
- [x] Composing Class Names —
cx
- [x] Generate Class Names —
- [ ] Custom Instances
- [x] Server Side Rendering
Usage
$ npm i @calmery-chan/aleph-plugin-emotion
// aleph.config.ts
import type { Config } from "https://deno.land/x/[email protected]/types.d.ts";
import emotion from "./node_modules/@calmery-chan/aleph-plugin-emotion/plugin.ts";
export default <Config> {
plugins: [emotion],
};
Internally, the React component is compiled using Babel, and then the CSS is
extracted using the extractCritical
function in
@emotion/server. Therefore, if
you import the npm package directly from esm.sh, etc., it
will fail to compile using Babel. Use
import_map.json and add
the npm package using npm install
.
// import_map.json
{
"imports": {
"@emotion/css": "https://esm.sh/@emotion/[email protected]",
"react": "https://esm.sh/[email protected]"
}
}
// pages/index.ts
// import { css } from "https://esm.sh/@emotion/[email protected]";
// import React from "https://esm.sh/[email protected]";
import { css } from "@emotion/css";
import React from "react";
const container = css`
background: #000;
color: #FFF;
`;
export default () => {
return (
<div className={container}>
Hello World
</div>
);
};
$ npm i -D @emotion/css react
$ aleph dev
See example.