Node.js: Difference between revisions
m
Add nextjs project example
Malteneuss (talk | contribs) m (Fix nix build --print-out-paths) |
Malteneuss (talk | contribs) m (Add nextjs project example) |
||
(One intermediate revision by the same user not shown) | |||
Line 200: | Line 200: | ||
import localFont from "next/font/local"; | import localFont from "next/font/local"; | ||
const inter = localFont({ src: './Inter.ttf' }); | const inter = localFont({ src: './Inter.ttf' }); | ||
</syntaxhighlight>and place the Google fonts from Nixpkgs into the project, e.g. in a <code> | </syntaxhighlight>and place the Google fonts from Nixpkgs into the project, e.g. in a <code>preBuild</code> phase:<syntaxhighlight lang="nix"> | ||
buildNpmPackage { | buildNpmPackage { | ||
pname = "myproject"; | pname = "myproject"; | ||
Line 207: | Line 207: | ||
# see https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/cr/crabfit-frontend/package.nix | # see https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/cr/crabfit-frontend/package.nix | ||
preBuild = '' | |||
cp "${ | cp "${ | ||
google-fonts.override { fonts = [ "Inter" ]; } | google-fonts.override { fonts = [ "Inter" ]; } | ||
}/share/fonts/truetype/Inter[wght].ttf" src/app/Inter.ttf | }/share/fonts/truetype/Inter[slnt,wght].ttf" src/app/Inter.ttf | ||
''; | ''; | ||
Line 217: | Line 217: | ||
</syntaxhighlight>You can take a look at what fonts are available in the Nix <code>google-fonts</code> package by calling:<syntaxhighlight lang="shell"> | </syntaxhighlight>You can take a look at what fonts are available in the Nix <code>google-fonts</code> package by calling:<syntaxhighlight lang="shell"> | ||
ls -ahl $(nix build --no-link --print-out-paths nixpkgs#google-fonts)/share/fonts/truetype/ | ls -ahl $(nix build --no-link --print-out-paths nixpkgs#google-fonts)/share/fonts/truetype/ | ||
</syntaxhighlight> | </syntaxhighlight>Take a look at https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/homepage-dashboard/default.nix for further workarounds for Nextjs in Nix. | ||
== Example nix shell for Node.js development == | == Example nix shell for Node.js development == |