From 10b39c2dd8796d9a0b9ed1e4259b9ab5599946f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Tue, 22 Nov 2022 12:12:17 +0100 Subject: [PATCH] Fix build --- api/package.json | 1 + api/tsconfig.json | 12 ++++++++---- site/package.json | 2 +- site/vite.config.ts | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/api/package.json b/api/package.json index b3e194fd5..df5ab83b3 100644 --- a/api/package.json +++ b/api/package.json @@ -10,6 +10,7 @@ "license": "MIT", "type": "module", "main": "./dist/index.js", + "module": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { "test": "vitest", diff --git a/api/tsconfig.json b/api/tsconfig.json index 2c873b5d5..02178a9bf 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -2,8 +2,9 @@ "compilerOptions": { /* Basic Options */ "incremental": true, - "target": "ES2020", + "target": "ESNext", "module": "NodeNext", + "rootDir": "./", "outDir": "dist", "declaration": true, @@ -30,11 +31,14 @@ "resolveJsonModule": true, /* Advanced Options */ - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + + // remove this when vite support "NodeNext" : https://github.com/vitejs/vite/issues/10481 or https://github.com/vitejs/vite/issues/8993 + "skipLibCheck": true }, "ts-node": { "esm": true }, - "include": ["source"], - "exclude": ["**/node_modules", "**/dist", "vitest.config.ts"] + "include": ["source", "vitest.config.ts"], + "exclude": ["**/dist"] } diff --git a/site/package.json b/site/package.json index 3aab9689f..e4bd05c8c 100644 --- a/site/package.json +++ b/site/package.json @@ -24,7 +24,7 @@ "start:axe-debugging": "VITE_AXE_CORE_ENABLED=true vite dev", "start:netlify": "sed 's|:SITE_EN|/infrance|g' netlify.base.toml | sed 's|:SITE_FR|/mon-entreprise|g' | sed 's|:API_URL|http://localhost:3004|g' | sed 's|\\[\\[redirects\\]\\]|\\[\\[redirects\\]\\]\\n force = true|g' > netlify.toml && HMR_CLIENT_PORT=8888 netlify dev", "build": "NODE_OPTIONS='--max-old-space-size=6144'; yarn build:sitemap && vite build && yarn build:iframe-script", - "build:ssr": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --ssr ./source/entry-server.tsx --outDir ./dist/ssr --emptyOutDir && echo '{\"module\": \"commonjs\"}' > dist/package.json", + "build:ssr": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --ssr ./source/entry-server.tsx --outDir ./dist/ssr --emptyOutDir && echo '{\"type\": \"module\"}' > dist/package.json", "build:prerender": "ts-node-esm prerender.ts", "build:iframe-script": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --config vite-iframe-script.config.ts", "build:sitemap": "ts-node-esm scripts/build-sitemap.ts", diff --git a/site/vite.config.ts b/site/vite.config.ts index b2a2c1df7..4645f23e0 100644 --- a/site/vite.config.ts +++ b/site/vite.config.ts @@ -119,6 +119,22 @@ export default defineConfig(({ command, mode }) => ({ // Optimize cjs deps from publicodes include: ['publicodes > moo', 'publicodes > nearley'], }, + ssr: { + /** + * Prevent listed dependencies from being externalized for SSR build cause some + * packages are not esm ready or package.json setup seems wrong, wait this pr to be merge: + * react-spectrum: https://github.com/adobe/react-spectrum/pull/3630 + * markdown-to-jsx: https://github.com/probablyup/markdown-to-jsx/pull/414 + * styled-components: https://github.com/styled-components/styled-components/issues/3601 + * publicodes-react: Add type module + */ + noExternal: [ + /react-aria|react-stately|internationalized/, + /markdown-to-jsx/, + /styled-components|emotion/, + /publicodes-react/, // TODO remove this after publicodes-react upgrade + ], + }, })) type MultipleSPAOptions = {