Skip to content

Commit a3391f3

Browse files
committed
[compiler] Compile lib
Add and compile a simple hook with rollup and babel.
1 parent bafcdb5 commit a3391f3

File tree

5 files changed

+638
-7
lines changed

5 files changed

+638
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const plugins = [
2+
[
3+
'babel-plugin-react-compiler',
4+
{
5+
target: '18',
6+
},
7+
],
8+
];
9+
10+
module.exports = {plugins};
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
throw new Error('Not implemented yet');
1+
import {useState, useEffect} from 'react';
2+
3+
export function useTime() {
4+
const [time, setTime] = useState(() => new Date());
5+
useEffect(() => {
6+
const id = setInterval(() => {
7+
setTime(new Date());
8+
}, 1000);
9+
return () => clearInterval(id);
10+
}, []);
11+
12+
return time;
13+
}

compiler/fixtures/runtime-compat/lib/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@
22
"name": "runtime-compat-lib",
33
"version": "0.0.0",
44
"description": "Testing ground for libraries compiled with React Compiler",
5-
"main": "index.js",
5+
"main": "dist/index.js",
66
"scripts": {
7+
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
78
"test": "echo 'no tests'"
89
},
910
"license": "MIT",
1011
"devDependencies": {
1112
"@babel/cli": "^7.25.7",
1213
"@babel/core": "^7.25.7",
1314
"@babel/preset-env": "^7.25.7",
14-
"babel-plugin-react-compiler": "0.0.0-experimental-58c2b1c-20241009"
15+
"@rollup/plugin-babel": "^6.0.4",
16+
"@rollup/plugin-json": "^6.1.0",
17+
"babel-plugin-react-compiler": "0.0.0-experimental-58c2b1c-20241009",
18+
"@rollup/plugin-terser": "^0.4.4",
19+
"react": "19.0.0-beta-26f2496093-20240514",
20+
"react-dom": "19.0.0-beta-26f2496093-20240514",
21+
"rimraf": "5",
22+
"rollup": "^4.22.4",
23+
"rollup-plugin-banner2": "^1.2.3",
24+
"rollup-plugin-prettier": "^4.1.1"
1525
},
1626
"dependencies": {
1727
"react-compiler-runtime": "0.0.0-experimental-8d8e73f-20241009"
28+
},
29+
"peerDependencies": {
30+
"react": "^18 || ^19"
1831
}
1932
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import json from '@rollup/plugin-json';
9+
import terser from '@rollup/plugin-terser';
10+
import prettier from 'rollup-plugin-prettier';
11+
import banner2 from 'rollup-plugin-banner2';
12+
import babel from '@rollup/plugin-babel';
13+
14+
const ROLLUP_CONFIG = {
15+
input: 'index.js',
16+
output: {
17+
file: 'dist/index.js',
18+
format: 'esm',
19+
sourcemap: false,
20+
exports: 'named',
21+
},
22+
plugins: [
23+
json(),
24+
babel({babelHelpers: 'bundled'}),
25+
terser({
26+
format: {
27+
comments: false,
28+
},
29+
compress: false,
30+
mangle: false,
31+
}),
32+
prettier(),
33+
banner2(
34+
() => `/**
35+
* Copyright (c) Meta Platforms, Inc. and affiliates.
36+
*
37+
* This source code is licensed under the MIT license found in the
38+
* LICENSE file in the root directory of this source tree.
39+
*
40+
* @lightSyntaxTransform
41+
* @noflow
42+
* @nolint
43+
* @preventMunge
44+
* @preserve-invariant-messages
45+
*/
46+
`
47+
),
48+
],
49+
};
50+
51+
export default ROLLUP_CONFIG;

0 commit comments

Comments
 (0)