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
2 changes: 2 additions & 0 deletions docs/guide/essentials/entrypoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ When you define a Bookmarks entrypoint, WXT will automatically update the manife
:patterns="[
['content.[jt]sx?', 'content-scripts/content.js'],
['content/index.[jt]sx?', 'content-scripts/content.js'],
['content.{name}.[jt]sx?', 'content-scripts/{name}.js'],
['content.{name}/index.[jt]sx?', 'content-scripts/{name}.js'],
['{name}.content.[jt]sx?', 'content-scripts/{name}.js'],
['{name}.content/index.[jt]sx?', 'content-scripts/{name}.js'],
]"
Expand Down
8 changes: 7 additions & 1 deletion packages/wxt/src/core/builders/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,13 @@ export async function createViteBuilder(
const requireDefaultExport = (path: string, mod: any) => {
const relativePath = relative(wxtConfig.root, path);
if (mod?.default == null) {
const defineFn = relativePath.includes('.content')
const isContentScript =
relativePath.includes('.content') ||
relativePath.includes('/content.') ||
relativePath.includes('\\content.') ||
relativePath.includes('/content/') ||
relativePath.includes('\\content\\');
const defineFn = isContentScript
? 'defineContentScript'
: relativePath.includes('background')
? 'defineBackground'
Expand Down
2 changes: 2 additions & 0 deletions packages/wxt/src/core/utils/__tests__/entrypoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('Entrypoint Utils', () => {
[resolve(entrypointsDir, 'example.sandbox/index.html'), 'example'],
[resolve(entrypointsDir, 'some.content/index.ts'), 'some'],
[resolve(entrypointsDir, 'overlay.content.ts'), 'overlay'],
[resolve(entrypointsDir, 'content.overlay.ts'), 'overlay'],
[resolve(entrypointsDir, 'content.overlay/index.ts'), 'overlay'],
])('should convert %s to %s', (inputPath, expected) => {
const actual = getEntrypointName(entrypointsDir, inputPath);
expect(actual).toBe(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ describe('findEntrypoints', () => {
skipped: false,
},
],
[
'content.overlay.ts',
{
type: 'content-script',
name: 'overlay',
inputPath: resolve(config.entrypointsDir, 'content.overlay.ts'),
outputDir: resolve(config.outDir, 'content-scripts'),
skipped: false,
},
],
[
'overlay.content.ts',
{
Expand All @@ -184,6 +194,16 @@ describe('findEntrypoints', () => {
skipped: false,
},
],
[
'content.overlay/index.ts',
{
type: 'content-script',
name: 'overlay',
inputPath: resolve(config.entrypointsDir, 'content.overlay/index.ts'),
outputDir: resolve(config.outDir, 'content-scripts'),
skipped: false,
},
],
[
'overlay.content/index.ts',
{
Expand Down Expand Up @@ -626,6 +646,17 @@ describe('findEntrypoints', () => {
skipped: false,
},
],
[
'content.overlay.css',
{
type: 'content-script-style',
name: 'overlay',
inputPath: resolve(config.entrypointsDir, 'content.overlay.css'),
outputDir: resolve(config.outDir, 'content-scripts'),
options: {},
skipped: false,
},
],
[
'overlay.content.css',
{
Expand All @@ -648,6 +679,17 @@ describe('findEntrypoints', () => {
skipped: false,
},
],
[
'content.overlay/index.css',
{
type: 'content-script-style',
name: 'overlay',
inputPath: resolve(config.entrypointsDir, 'content.overlay/index.css'),
outputDir: resolve(config.outDir, 'content-scripts'),
options: {},
skipped: false,
},
],
[
'overlay.content/index.css',
{
Expand Down
4 changes: 4 additions & 0 deletions packages/wxt/src/core/utils/building/find-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,15 @@ const PATH_GLOB_TO_TYPE_MAP: Record<string, Entrypoint['type']> = {

'content.[jt]s?(x)': 'content-script',
'content/index.[jt]s?(x)': 'content-script',
'content.*.[jt]s?(x)': 'content-script',
'content.*/index.[jt]s?(x)': 'content-script',
'*.content.[jt]s?(x)': 'content-script',
'*.content/index.[jt]s?(x)': 'content-script',
[`content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`content.*.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`content.*/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',

'popup.html': 'popup',
Expand Down
6 changes: 6 additions & 0 deletions packages/wxt/src/core/utils/entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export function getEntrypointName(
// type: Entrypoint['type'],
): string {
const relativePath = path.relative(entrypointsDir, inputPath);
if (relativePath.startsWith('content.')) {
const rest = relativePath.slice('content.'.length);
const [first, second] = rest.split(/[/\\]/, 2);
if (second != null || first.includes('.')) return first.split('.', 2)[0];
}

// Grab the string up to the first . or / or \\
const name = relativePath.split(/[./\\]/, 2)[0];

Expand Down
2 changes: 2 additions & 0 deletions packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ export interface BaseEntrypoint {
* - `sandbox/index.html` &rarr; `sandbox`
* - `overlay.content.ts` &rarr; `overlay`
* - `overlay.content/index.ts` &rarr; `overlay`
* - `content.overlay.ts` &rarr; `overlay`
* - `content.overlay/index.ts` &rarr; `overlay`
*
* The name is used when generating an output file:
* `<entrypoint.outputDir>/<entrypoint.name>.<ext>`
Expand Down