This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support inline style for ssr (#518)
* feat: inline style for less * feat: classname to style * feat: esbuild inline style * feat: transform styles * fix: compat for less module * fix: less rule * feat: ignore * docs: ignore * refactor: to ts * test: inline-style * chore: update lock * fix: deps * refactor: enable esbuild inline style loader only in ssr * fix: validate for ignore plugins * refactor: to pure functions * feat: sync syntaxFeatures * fix: lint * Update rax-inline-style.test.ts
- Loading branch information
1 parent
2d55abc
commit 16e0afa
Showing
24 changed files
with
3,768 additions
and
1,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chrome 55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig } from '@ice/app'; | ||
import compatRax from '@ice/plugin-rax-compat'; | ||
|
||
export default defineConfig({ | ||
publicPath: '/', | ||
plugins: [compatRax({ | ||
inlineStyle: true, | ||
})], | ||
server: { | ||
bundle: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "rax-project", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"start": "ice start", | ||
"build": "ice build" | ||
}, | ||
"description": "", | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@ice/app": "workspace:*", | ||
"@ice/plugin-rax-compat": "workspace:*", | ||
"@ice/runtime": "workspace:*", | ||
"rax": "^1.2.2", | ||
"rax-image": "^2.4.1", | ||
"rax-is-valid-element": "^1.0.0", | ||
"rax-text": "^2.2.0", | ||
"rax-view": "^2.3.0", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.2", | ||
"webpack": "^5.73.0" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineAppConfig } from 'ice'; | ||
|
||
export default defineAppConfig({ | ||
app: { | ||
rootId: 'app', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createElement } from 'rax'; | ||
import Image from 'rax-image'; | ||
|
||
import styles from './index.module.less'; | ||
|
||
export default (props) => { | ||
const { uri } = props; | ||
const source = { uri }; | ||
return <Image className={styles['logo']} source={source} />; | ||
}; |
5 changes: 5 additions & 0 deletions
5
examples/rax-inline-style/src/components/Logo/index.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.logo { | ||
width: 200rpx; | ||
height: 180rpx; | ||
margin-bottom: 20rpx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createElement } from 'rax'; | ||
import Text from 'rax-text'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
export default () => { | ||
return <Text className={styles['title']}>Welcome to Your Rax App</Text>; | ||
}; |
5 changes: 5 additions & 0 deletions
5
examples/rax-inline-style/src/components/Title/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.title { | ||
font-size: 45rpx; | ||
font-weight: bold; | ||
margin: 20rpx 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* @jsx createElement */ | ||
import { createElement } from 'rax'; | ||
import { Meta, Title, Links, Main, Scripts } from 'ice'; | ||
|
||
function Document() { | ||
return ( | ||
<html> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<meta name="description" content="ICE 3.0 Demo" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover" /> | ||
<Meta /> | ||
<Title /> | ||
<Links /> | ||
</head> | ||
<body> | ||
<Main /> | ||
<Scripts /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default Document; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
font-size: 14px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.title { | ||
color: red; | ||
margin-left: 10rpx; | ||
} | ||
|
||
.data { | ||
margin-top: 10px; | ||
} | ||
|
||
.homeContainer { | ||
align-items: center; | ||
margin-top: 200rpx; | ||
} | ||
|
||
.homeInfo { | ||
font-size: 36rpx; | ||
margin: 8rpx 0; | ||
color: #555; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createElement, useEffect, useRef } from 'rax'; | ||
import View from 'rax-view'; | ||
import Text from 'rax-text'; | ||
import Logo from '@/components/Logo'; | ||
import Title from '@/components/Title'; | ||
import './index.css'; | ||
|
||
export default function Home() { | ||
const ref = useRef(); | ||
useEffect(() => { | ||
if (ref.current) { | ||
console.log('ref for View', ref); | ||
} | ||
}, []); | ||
return ( | ||
<View | ||
ref={ref} | ||
className="homeContainer" | ||
style={{ | ||
width: '750rpx', | ||
}} | ||
onAppear={() => { console.log('view appear'); }} | ||
> | ||
<Logo uri="//gw.alicdn.com/tfs/TB1MRC_cvb2gK0jSZK9XXaEgFXa-1701-1535.png" /> | ||
<Title /> | ||
<Text className="homeInfo">More information about Rax</Text> | ||
<Text className="homeInfo">Visit https://rax.js.org</Text> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
declare module '*.module.less' { | ||
const classes: { [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.css' { | ||
const classes: { [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.scss' { | ||
const classes: { [key: string]: string }; | ||
export default classes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"compileOnSave": false, | ||
"buildOnSave": false, | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es6", | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es6", "dom"], | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"rootDir": "./", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": false, | ||
"importHelpers": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@/*": ["./src/*"], | ||
"ice": [".ice"] | ||
} | ||
}, | ||
"include": ["src", ".ice", "ice.config.*"], | ||
"exclude": ["node_modules", "build", "public"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { Plugin, PluginBuild } from 'esbuild'; | ||
|
||
interface IgnorePattern { | ||
resourceRegExp: RegExp; | ||
contextRegExp?: RegExp; | ||
} | ||
|
||
const igonrePlugin = (ignores: IgnorePattern[] = []): Plugin => { | ||
return { | ||
name: 'esbuild-ignore', | ||
setup(build: PluginBuild) { | ||
if (!Array.isArray(ignores)) { | ||
return; | ||
} | ||
|
||
for (const ignorePattern of ignores) { | ||
build.onResolve({ filter: ignorePattern.resourceRegExp }, args => { | ||
if (ignorePattern.contextRegExp) { | ||
if (args.resolveDir.match(ignorePattern.contextRegExp)) { | ||
return { | ||
path: args.path, | ||
namespace: 'ignore', | ||
}; | ||
} else { | ||
return { | ||
path: args.path, | ||
}; | ||
} | ||
} | ||
|
||
return { | ||
path: args.path, | ||
namespace: 'ignore', | ||
}; | ||
}); | ||
} | ||
|
||
build.onLoad({ filter: /.*/, namespace: 'ignore' }, async () => { | ||
return { | ||
contents: '', | ||
}; | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
export default igonrePlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
16e0afa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ice-v3 – ./
ice-v3-ice-v3.vercel.app
ice-v3-git-release-next-ice-v3.vercel.app
ice-v3.vercel.app