Skip to content

Commit

Permalink
[compiler] Compile lib
Browse files Browse the repository at this point in the history
Add and compile a simple hook with rollup and babel.
  • Loading branch information
poteto committed Oct 10, 2024
1 parent f7df09f commit 8e72409
Show file tree
Hide file tree
Showing 5 changed files with 638 additions and 7 deletions.
10 changes: 10 additions & 0 deletions compiler/fixtures/runtime-compat/lib/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const plugins = [
[
'babel-plugin-react-compiler',
{
target: '18',
},
],
];

module.exports = {plugins};
14 changes: 13 additions & 1 deletion compiler/fixtures/runtime-compat/lib/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
throw new Error('Not implemented yet');
import {useState, useEffect} from 'react';

export function useTime() {
const [time, setTime] = useState(() => new Date());
useEffect(() => {
const id = setInterval(() => {
setTime(new Date());
}, 1000);
return () => clearInterval(id);
}, []);

return time;
}
17 changes: 15 additions & 2 deletions compiler/fixtures/runtime-compat/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@
"name": "runtime-compat-lib",
"version": "0.0.0",
"description": "Testing ground for libraries compiled with React Compiler",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
"test": "echo 'no tests'"
},
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.25.7",
"@babel/core": "^7.25.7",
"@babel/preset-env": "^7.25.7",
"babel-plugin-react-compiler": "0.0.0-experimental-58c2b1c-20241009"
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-json": "^6.1.0",
"babel-plugin-react-compiler": "0.0.0-experimental-58c2b1c-20241009",
"@rollup/plugin-terser": "^0.4.4",
"react": "19.0.0-beta-26f2496093-20240514",
"react-dom": "19.0.0-beta-26f2496093-20240514",
"rimraf": "5",
"rollup": "^4.22.4",
"rollup-plugin-banner2": "^1.2.3",
"rollup-plugin-prettier": "^4.1.1"
},
"dependencies": {
"react-compiler-runtime": "0.0.0-experimental-8d8e73f-20241009"
},
"peerDependencies": {
"react": "^18 || ^19"
}
}
51 changes: 51 additions & 0 deletions compiler/fixtures/runtime-compat/lib/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import prettier from 'rollup-plugin-prettier';
import banner2 from 'rollup-plugin-banner2';
import babel from '@rollup/plugin-babel';

const ROLLUP_CONFIG = {
input: 'index.js',
output: {
file: 'dist/index.js',
format: 'esm',
sourcemap: false,
exports: 'named',
},
plugins: [
json(),
babel({babelHelpers: 'bundled'}),
terser({
format: {
comments: false,
},
compress: false,
mangle: false,
}),
prettier(),
banner2(
() => `/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @lightSyntaxTransform
* @noflow
* @nolint
* @preventMunge
* @preserve-invariant-messages
*/
`
),
],
};

export default ROLLUP_CONFIG;
Loading

0 comments on commit 8e72409

Please sign in to comment.