diff --git a/examples/2.1-simple-express-only-client/build.js b/examples/2.1-simple-express-only-client/build.js new file mode 100644 index 0000000..26d9180 --- /dev/null +++ b/examples/2.1-simple-express-only-client/build.js @@ -0,0 +1,38 @@ +const { isomorphicCompiler, backendCompiler, frontendCompiler, getArgs } = require('@rockpack/compiler'); + +if (getArgs().client) { + frontendCompiler({ + src: 'src/client.jsx', + global: { + client: true + }, + dist: 'public', + babel: { + plugins: [ + '@issr/babel-plugin' + ] + }, + }); +} else { + isomorphicCompiler( + frontendCompiler({ + src: 'src/client.jsx', + dist: 'public', + babel: { + plugins: [ + '@issr/babel-plugin' + ] + }, + }), + backendCompiler({ + src: 'src/server.jsx', + dist: 'dist', + babel: { + plugins: [ + '@issr/babel-plugin' + ] + }, + }) + ); + +} diff --git a/examples/2.1-simple-express-only-client/package.json b/examples/2.1-simple-express-only-client/package.json new file mode 100644 index 0000000..e8cc711 --- /dev/null +++ b/examples/2.1-simple-express-only-client/package.json @@ -0,0 +1,20 @@ +{ + "name": "@issr/example-2.1", + "version": "1.0.0", + "scripts": { + "start": "cross-env NODE_ENV=development node build", + "start:client": "cross-env NODE_ENV=development node build --client", + "build": "cross-env NODE_ENV=production node build" + }, + "dependencies": { + "@issr/core": "1.0.0", + "express": "^4.17.1", + "react": "16.13.1", + "react-dom": "16.13.1", + "serialize-javascript": "3.0.0" + }, + "devDependencies": { + "@issr/babel-plugin": "1.0.0", + "@rockpack/compiler": "1.9.0" + } +} diff --git a/examples/2.1-simple-express-only-client/src/App.jsx b/examples/2.1-simple-express-only-client/src/App.jsx new file mode 100644 index 0000000..0894007 --- /dev/null +++ b/examples/2.1-simple-express-only-client/src/App.jsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { useSsrState, useSsrEffect } from '@issr/core'; + +const asyncFn = () => new Promise((resolve) => setTimeout(() => resolve('Hello world'), 1000)); + +export const App = () => { + const [state, setState] = useSsrState('text here'); + + useSsrEffect(async () => { + const data = await asyncFn() + setState(data); + }); + + return ( +