Unverified Commit 9ec041ef authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Update font loader output path (#40868)

Updates the output path so it's the same as when font files are imported
in CSS: `url(./font.woff2)`

Also adds missing font types to next package.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent bb1dd470
......@@ -22,7 +22,7 @@ export default async function nextFontLoader(this: any) {
const interpolatedName = loaderUtils.interpolateName(
this,
// Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded
`static/fonts/[hash]${preload ? '.p' : ''}.${ext}`,
`static/media/[hash]${preload ? '.p' : ''}.${ext}`,
opts
)
const outputPath = `${assetPrefix}/_next/${interpolatedName}`
......
......@@ -47,7 +47,8 @@
"types/index.d.ts",
"types/global.d.ts",
"types/compiled.d.ts",
"image-types/global.d.ts"
"image-types/global.d.ts",
"font"
],
"bin": {
"next": "./dist/bin/next"
......
......@@ -46,7 +46,7 @@ describe('@next/font/google basepath', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/dashboard/_next/static/fonts/0812efcfaefec5ea.p.woff2',
href: '/dashboard/_next/static/media/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......@@ -72,7 +72,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/4a7f86e553ee7e51.p.woff2',
href: '/_next/static/media/4a7f86e553ee7e51.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......@@ -96,7 +96,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......@@ -104,7 +104,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/9a7e84b4dd095b33.p.woff2',
href: '/_next/static/media/9a7e84b4dd095b33.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......@@ -128,7 +128,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/0812efcfaefec5ea.p.woff2',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......@@ -136,7 +136,7 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/fonts/2a931eed088772c9.p.woff2',
href: '/_next/static/media/2a931eed088772c9.p.woff2',
rel: 'preload',
type: 'font/woff2',
})
......
......@@ -7,7 +7,7 @@ describe('@next/font/local', () => {
functionName: '',
data: [{ src: './my-font.woff2' }],
config: {},
emitFontFile: () => '/_next/static/fonts/my-font.woff2',
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -17,7 +17,7 @@ describe('@next/font/local', () => {
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
src: url(/_next/static/fonts/my-font.woff2) format('woff2');
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
}"
`)
......@@ -30,7 +30,7 @@ font-display: optional;
{ src: [{ file: './my-font.woff2', unicodeRange: 'unicode-range' }] },
],
config: {},
emitFontFile: () => '/_next/static/fonts/my-font.woff2',
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -40,7 +40,7 @@ font-display: optional;
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
src: url(/_next/static/fonts/my-font.woff2) format('woff2');
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
unicode-range: unicode-range;
}"
......@@ -52,7 +52,7 @@ unicode-range: unicode-range;
functionName: '',
data: [{ src: [{ file: './my-font.woff2' }] }],
config: {},
emitFontFile: () => '/_next/static/fonts/my-font.woff2',
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -62,7 +62,7 @@ unicode-range: unicode-range;
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
src: url(/_next/static/fonts/my-font.woff2) format('woff2');
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
}"
`)
......@@ -73,7 +73,7 @@ font-display: optional;
functionName: '',
data: [{ src: './my-font.woff2', weight: '100 900', style: 'italic' }],
config: {},
emitFontFile: () => '/_next/static/fonts/my-font.woff2',
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -83,7 +83,7 @@ font-display: optional;
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
src: url(/_next/static/fonts/my-font.woff2) format('woff2');
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 100 900;
font-style: italic;
......@@ -108,7 +108,7 @@ font-style: italic;
},
],
config: {},
emitFontFile: () => '/_next/static/fonts/my-font.woff2',
emitFontFile: () => '/_next/static/media/my-font.woff2',
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -118,7 +118,7 @@ font-style: italic;
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font';
src: url(/_next/static/fonts/my-font.woff2) format('woff2');
src: url(/_next/static/media/my-font.woff2) format('woff2');
font-display: optional;
font-weight: 100 900;
font-style: italic;
......@@ -147,7 +147,7 @@ size-adjust: sizeAdjust;
},
],
config: {},
emitFontFile: () => `/_next/static/fonts/font-file`,
emitFontFile: () => `/_next/static/media/font-file`,
resolve: jest.fn(),
fs: {
readFile: (_, cb) => cb(null, 'fontdata'),
......@@ -157,31 +157,31 @@ size-adjust: sizeAdjust;
expect(css).toMatchInlineSnapshot(`
"@font-face {
font-family: 'my-font1';
src: url(/_next/static/fonts/font-file) format('woff');
src: url(/_next/static/media/font-file) format('woff');
font-display: optional;
unicode-range: 1;
}
@font-face {
font-family: 'my-font1';
src: url(/_next/static/fonts/font-file) format('woff2');
src: url(/_next/static/media/font-file) format('woff2');
font-display: optional;
unicode-range: 2;
}
@font-face {
font-family: 'my-font1';
src: url(/_next/static/fonts/font-file) format('embedded-opentype');
src: url(/_next/static/media/font-file) format('embedded-opentype');
font-display: optional;
unicode-range: 3;
}
@font-face {
font-family: 'my-font1';
src: url(/_next/static/fonts/font-file) format('truetype');
src: url(/_next/static/media/font-file) format('truetype');
font-display: optional;
unicode-range: 4;
}
@font-face {
font-family: 'my-font1';
src: url(/_next/static/fonts/font-file) format('opentype');
src: url(/_next/static/media/font-file) format('opentype');
font-display: optional;
unicode-range: 5;
}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment