Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Make publicDir and modulesDir relative to project root #1216

Merged
merged 3 commits into from
Nov 28, 2024
Merged
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
6 changes: 5 additions & 1 deletion docs/guide/essentials/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ img.src = imageUrl;

## `/public` Directory

Files inside `<srcDir>/public/` are copied into the output folder as-is, without being processed by WXT's bundler.
Files inside `<rootDir>/public/` are copied into the output folder as-is, without being processed by WXT's bundler.

Here's how you access them:

Expand All @@ -54,6 +54,10 @@ img.src = imageUrl;

:::

:::warning
Assets in the `public/` directory are **_not_** accessible in content scripts by default. To use a public asset in a content script, you must add it to your manifest's [`web_accessible_resources` array](/api/reference/wxt/type-aliases/UserManifest#web-accessible-resources).
:::

## Inside Content Scripts

Assets inside content scripts are a little different. By default, when you import an asset, it returns just the path to the asset. This is because Vite assumes you're loading assets from the same hostname.
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ After enabling it, your project structure should look like this:
📂 {rootDir}/
📁 .output/
📁 .wxt/
📁 modules/
📁 public/
📂 src/
📁 assets/
📁 components/
📁 composables/
📁 entrypoints/
📁 hooks/
📁 modules/
📁 public/
📁 utils/
📄 app.config.ts
📄 .env
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ However, it does have one major downside:
helloWorld: Hello world!
```

> `@wxt-dev/i18n` supports the standard messages format, so if you already have localization files at `<srcDir>/public/_locale/<lang>/messages.json`, you don't need to convert them to YAML or refactor them - just move them to `<srcDir>/locales/<lang>.json` and they'll just work out of the box!
> `@wxt-dev/i18n` supports the standard messages format, so if you already have localization files at `<rootDir>/public/_locale/<lang>/messages.json`, you don't need to convert them to YAML or refactor them - just move them to `<srcDir>/locales/<lang>.json` and they'll just work out of the box!

4. To get a translation, use the auto-imported `i18n` object or import it manually:

Expand Down
4 changes: 2 additions & 2 deletions packages/wxt/src/core/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ export async function resolveConfig(
srcDir,
mergedConfig.entrypointsDir ?? 'entrypoints',
);
const modulesDir = path.resolve(srcDir, mergedConfig.modulesDir ?? 'modules');
if (await isDirMissing(entrypointsDir)) {
logMissingDir(logger, 'Entrypoints', entrypointsDir);
}
const modulesDir = path.resolve(root, mergedConfig.modulesDir ?? 'modules');
const filterEntrypoints = mergedConfig.filterEntrypoints?.length
? new Set(mergedConfig.filterEntrypoints)
: undefined;
const publicDir = path.resolve(srcDir, mergedConfig.publicDir ?? 'public');
const publicDir = path.resolve(root, mergedConfig.publicDir ?? 'public');
const typesDir = path.resolve(wxtDir, 'types');
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? '.output');
const modeSuffixes: Record<string, string | undefined> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface InlineConfig {
*/
entrypointsDir?: string;
/**
* @default "${config.srcDir}/modules"
* @default "${config.root}/modules"
*/
modulesDir?: string;
/**
Expand Down