Skip to content

Commit

Permalink
fix: Support srcDir config
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jun 25, 2023
1 parent 1a25f2b commit 739d19f
Show file tree
Hide file tree
Showing 20 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions demo/exvite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from 'exvite';

export default defineConfig({
srcDir: 'src',
storeIds: {
chrome: '123',
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
2 changes: 1 addition & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["../tsconfig.base.json", "./.exvite/tsconfig.json"]
"extends": ["../tsconfig.base.json", "./src/.exvite/tsconfig.json"]
}
4 changes: 2 additions & 2 deletions src/utils/createFsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { dirname, resolve } from 'path';
*
* @param srcDir Absolute path to source directory. See `InternalConfig.srcDir`
*/
export function createFsCache(srcDir: string): FsCache {
export function createFsCache(exviteDir: string): FsCache {
const getPath = (key: string) =>
resolve(srcDir, '.exvite/cache', encodeURIComponent(key));
resolve(exviteDir, 'cache', encodeURIComponent(key));

return {
async set(key: string, value: string): Promise<void> {
Expand Down
12 changes: 11 additions & 1 deletion src/utils/getInternalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function getInternalConfig(
logger,
vite: config.vite ?? {},
manifest: config.manifest ?? {},
fsCache: createFsCache(srcDir),
fsCache: createFsCache(exviteDir),
imports: config.imports ?? {},
};

Expand All @@ -69,6 +69,16 @@ export async function getInternalConfig(
// Merge inline and user configs
const merged = vite.mergeConfig(baseConfig, userConfig) as InternalConfig;

// Ensure user customized directories are absolute
merged.srcDir = userConfig.srcDir ? resolve(root, merged.srcDir) : root;
merged.entrypointsDir = resolve(
merged.srcDir,
userConfig.entrypointsDir ?? 'entrypoints',
);
merged.publicDir = resolve(merged.srcDir, userConfig.publicDir ?? 'public');
merged.exviteDir = resolve(merged.srcDir, '.exvite');
merged.typesDir = resolve(merged.exviteDir, 'types');

// Customize the default vite config
merged.vite.root = root;
merged.vite.configFile = false;
Expand Down
1 change: 1 addition & 0 deletions src/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function writeManifest(
? JSON.stringify(manifest)
: JSON.stringify(manifest, null, 2);

await fs.ensureDir(config.outDir);
await fs.writeFile(resolve(config.outDir, 'manifest.json'), str, 'utf-8');

output.unshift({
Expand Down

0 comments on commit 739d19f

Please sign in to comment.