WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this file? Will the absence of this file cause test failures?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I could make it optional but IIRC there is some other code that actually relies on there always being a package.json anyway, except that it's not hit by the tests so the fixture worked before

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 9 additions & 2 deletions packages/plugin/vite/src/config/vite.main.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from 'node:path';

import fs from 'fs-extra';
import { type ConfigEnv, mergeConfig, type UserConfig } from 'vite';

import {
Expand All @@ -11,7 +14,11 @@ export function getConfig(
forgeEnv: ConfigEnv<'build'>,
userConfig: UserConfig = {},
): UserConfig {
const { forgeConfigSelf } = forgeEnv;
const { forgeConfigSelf, root } = forgeEnv;
const packageJson = JSON.parse(
fs.readFileSync(path.join(root, 'package.json'), { encoding: 'utf-8' }),
);

const define = getBuildDefine(forgeEnv);
const config: UserConfig = {
build: {
Expand All @@ -34,7 +41,7 @@ export function getConfig(
config.build!.lib = {
entry: forgeConfigSelf.entry,
fileName: () => '[name].js',
formats: ['cjs'],
formats: packageJson.type !== 'module' ? ['cjs'] : ['es'],
};
}

Expand Down
Loading