Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Commit 98bc517

Browse files
add rollup config for server build
1 parent 1a39fc1 commit 98bc517

File tree

5 files changed

+110
-12
lines changed

5 files changed

+110
-12
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
},
2020
"scripts": {
2121
"dev": "vite build --watch",
22-
"build": "tsc && vite build"
22+
"build": "tsc && vite build && rollup -c"
2323
},
2424
"devDependencies": {
2525
"@remix-run/dev": "^1.0.5",
2626
"@remix-run/node": "^1.1.3",
2727
"@remix-run/react": "^1.0.5",
28+
"@rollup/plugin-typescript": "^8.3.0",
2829
"@types/babel__core": "^7.1.18",
2930
"@types/node": "^17.0.14",
3031
"@types/node-fetch": "^2.6.1",
@@ -37,6 +38,7 @@
3738
"react": ">=16.8",
3839
"react-dom": ">=16.8",
3940
"remix": ">=1.0.5",
41+
"rollup": "^2.67.2",
4042
"tailwindcss": "^3.0.18",
4143
"typescript": "^4.4.4",
4244
"vite": "^2.7.2"
@@ -47,6 +49,7 @@
4749
"remix": ">=1.0.5"
4850
},
4951
"dependencies": {
52+
"axios": "^0.26.0",
5053
"highlight.js": "^11.4.0",
5154
"node-fetch": "^3.2.0",
5255
"source-map": "^0.7.3"

pnpm-lock.yaml

Lines changed: 61 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import typescript from "@rollup/plugin-typescript";
2+
3+
export default {
4+
input: "src/server/index.ts",
5+
plugins: [typescript()],
6+
external: [
7+
"react",
8+
"react-dom",
9+
"remix",
10+
"source-map",
11+
"fs/promises",
12+
"axios",
13+
],
14+
output: [
15+
{
16+
file: "dist/server/remix-crash.umd.js",
17+
name: "RemixCrash",
18+
format: "umd",
19+
globals: {
20+
remix: "Remix",
21+
"source-map": "SourceMap",
22+
"fs/promises": "FSPromises",
23+
axios: "Axios",
24+
},
25+
},
26+
{
27+
file: "dist/server/remix-crash.es.js",
28+
format: "esm",
29+
globals: {
30+
remix: "Remix",
31+
"source-map": "SourceMap",
32+
"fs/promises": "FSPromises",
33+
axios: "Axios",
34+
},
35+
},
36+
],
37+
};

src/server/endpoints.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ActionFunction, LoaderFunction, json } from "remix";
22
import { SourceMapConsumer } from "source-map";
33
import { CORSResponse } from "./utils";
44
import { readFile } from "fs/promises";
5-
// import fetch from "node-fetch";
5+
import axios from "axios";
66

77
export const loader: LoaderFunction = () => {
88
if (process.env.NODE_ENV !== "development") {
@@ -17,9 +17,9 @@ export const action: ActionFunction = async ({ request }) => {
1717
throw new Response(null, { status: 404 });
1818
}
1919

20-
// fetch("https://jsonplaceholder.typicode.com/todos/1")
21-
// .then((response) => response.json())
22-
// .then((json) => console.log(json));
20+
axios("https://jsonplaceholder.typicode.com/todos/1")
21+
.then((response) => response.data)
22+
.then((data) => console.log(data));
2323

2424
const url = new URL(request.url);
2525
const root = process.cwd();

vite.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export default defineConfig(({ mode }) => {
1212
: {},
1313
build: {
1414
emptyOutDir: false,
15-
outDir: "dist/server",
15+
outDir: "dist/client",
1616
lib: {
17-
entry: path.resolve(__dirname, "src/server/index.ts"),
17+
entry: path.resolve(__dirname, "src/client/index.ts"),
1818
name: "RemixCrash",
1919
fileName: (format) => `remix-crash.${format}.js`,
2020
},
@@ -27,7 +27,7 @@ export default defineConfig(({ mode }) => {
2727
"remix",
2828
"source-map",
2929
"fs/promises",
30-
"node-fetch",
30+
"axios",
3131
],
3232
output: {
3333
// Provide global variables to use in the UMD build
@@ -38,7 +38,7 @@ export default defineConfig(({ mode }) => {
3838
remix: "Remix",
3939
"source-map": "SourceMap",
4040
"fs/promises": "FSPromises",
41-
"node-fetch": "NodeFetch",
41+
axios: "Axios",
4242
},
4343
},
4444
},

0 commit comments

Comments
 (0)