Skip to content

Commit

Permalink
Optimize field-kit dependencies in development.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Aug 31, 2023
1 parent d48f645 commit eb22547
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/field-kit/bin/field-scripts/develop-module/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -25,6 +26,18 @@ const fs = {
allow: [cwd, root],
};

/**
* Optimize dependencies for @farmos.org/field-kit, except @farmos.org/farmos-map.
* @see https://vitejs.dev/config/dep-optimization-options.html
*/
const pkgPath = path.resolve(root, 'package.json');
const pkgRaw = readFileSync(pkgPath, 'utf-8');
const pkg = JSON.parse(pkgRaw);
const { dependencies = {} } = pkg || {};
const exclude = ['@farmos.org/farmos-map'];
const include = Object.keys(dependencies).filter(d => !exclude.includes(d));
const optimizeDeps = { exclude, include };

const proxyPort = port => ({
target: `http://localhost:${port}`,
changeOrigin: true,
Expand Down Expand Up @@ -71,10 +84,7 @@ export default async function develop(options = {}) {
createVuePlugin({ jsx: true }),
viteCommonjs(),
],
optimizeDeps: {
exclude: ['@farmos.org/farmos-map'],
include: ['axios'],
},
optimizeDeps,
server: {
port,
fs,
Expand Down

0 comments on commit eb22547

Please sign in to comment.