Skip to content

Commit

Permalink
update entry-points build logic to allow for pnpm dev (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka authored Apr 1, 2024
1 parent b3d7625 commit 49f0ff9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ dist-ssr
*.key
.env

index.html
entry_points/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=18"
},
"scripts": {
"dev": "vite",
"dev": "cp ./template.html ./index.html && vite",
"build": "pnpm run build:generate-entry-points && tsc && vite build",
"build:inject-app-deeplinks": "sh scripts/inject-app-deeplinks.sh",
"build:inject-amplitude": "node scripts/inject-amplitude.js",
Expand Down
23 changes: 14 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import fs from 'fs';
import react from '@vitejs/plugin-react';
import fs from 'fs';
import path from 'path';
import sourcemaps from 'rollup-plugin-sourcemaps';
import { defineConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
import ViteRestart from 'vite-plugin-restart';
import sourcemaps from 'rollup-plugin-sourcemaps';
import svgr from 'vite-plugin-svgr';

const entryPointsDir = path.join(__dirname, 'entry-points');
const entryPointsExist = fs.existsSync(entryPointsDir);

const entryPoints = entryPointsExist
? fs.readdirSync(entryPointsDir).map((file) => `/entry-points/${file}`)
: [];

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
Expand All @@ -14,7 +21,7 @@ export default defineConfig(({ mode }) => ({
rollupOptions: {
// Needed for Abacus sourcemaps since Rollup doesn't load external sourcemaps by default.
// https://github.com/vitejs/vite/issues/11743
plugins: mode === 'development' ? [sourcemaps()] : []
plugins: mode === 'development' ? [sourcemaps()] : [],
},
resolve: {
alias: [
Expand Down Expand Up @@ -62,10 +69,8 @@ export default defineConfig(({ mode }) => ({
// Workaround is to use ViteRestart plugin + a generated file to trigger the restart.
// See https://github.com/vitejs/vite/issues/8619
ViteRestart({
restart: [
'local-abacus-hash',
]
})
restart: ['local-abacus-hash'],
}),
],
publicDir: 'public',
test: {
Expand All @@ -80,7 +85,7 @@ export default defineConfig(({ mode }) => ({
},
build: {
rollupOptions: {
input: fs.readdirSync('entry-points').map(file => `/entry-points/${file}`)
input: entryPoints,
},
},
}));

0 comments on commit 49f0ff9

Please sign in to comment.