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
17 changes: 16 additions & 1 deletion lib/build-esbuild/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,22 @@ async function assembleBuildOpts (src, dest, siteData, opts, modeOpts = {}) {
entryNames: watch ? '[dir]/[name]' : '[dir]/[name]-[hash]',
chunkNames: 'chunks/[ext]/[name]-[hash]',
jsx: 'automatic',
jsxImportSource: 'preact'
jsxImportSource: 'preact',
loader: {
'.png': 'dataurl',
'.jpg': 'dataurl',
'.jpeg': 'dataurl',
'.gif': 'dataurl',
'.svg': 'dataurl',
'.webp': 'dataurl',
'.avif': 'dataurl',
'.ico': 'file',
'.woff': 'file',
'.woff2': 'file',
'.ttf': 'file',
'.eot': 'file',
'.otf': 'file',
}
Comment thread
bcomnes marked this conversation as resolved.
}

const esbuildSettingsExtends = siteData.esbuildSettings
Expand Down
15 changes: 15 additions & 0 deletions test-cases/general-features/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ test.describe('general-features', () => {
const jsChunkFiles = files.filter(f => f.relname.match(/chunks\/js\/chunk-.+\.js$/))
assert.ok(jsChunkFiles.length > 0, 'at least one shared JS chunk was produced with a hashed name')

// Verify that CSS asset loaders work: images inline as data URLs, fonts are emitted as files
const globalCssFile = files.find(f => f.relname.match(/global-([A-Z0-9])\w+\.css$/))
if (globalCssFile) {
const cssContent = await readFile(path.join(dest, globalCssFile.relname), 'utf8')
assert.ok(
cssContent.includes('data:image/gif;base64,'),
'global CSS inlines GIF image as a base64 data URL'
)
} else {
assert.fail('Could not find global CSS output file to verify asset loaders')
}

const woff2Files = files.filter(f => f.relname.endsWith('.woff2'))
assert.ok(woff2Files.length > 0, 'woff2 font file was emitted to the output directory')

// Special test for global.data.js blogPostsHtml
const indexPath = path.join(dest, 'index.html')
try {
Expand Down
3 changes: 3 additions & 0 deletions test-cases/general-features/src/globals/global.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
@import 'mine.css/dist/mine.css';
@import 'mine.css/dist/layout.css';

.test-asset-icon { background-image: url('./test-icon.gif'); }
@font-face { font-family: 'TestFont'; src: url('./test-font.woff2'); }
1 change: 1 addition & 0 deletions test-cases/general-features/src/globals/test-font.woff2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wOF2placeholder
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.