刚开始使用Gatsby + Netlify。构建Netlify Starter Blog theme,但去除默认的NPM安装字体并希望托管我自己的字体。将woff
个文件放在src/components/fonts
中,将fonts.css
放在src/components
中。在import './fonts.css'
上方的Layout.js
中进行import ./layout.css
。在本地看起来不错,部署到Netlify失败,并显示以下日志。
已按照guide的gatsby-plugin-web-font-loader
NPM安装并添加:
{
resolve: `gatsby-plugin-web-font-loader`,
options: {
custom: {
families: [`ArtifexCF`, `Boston`],
urls: [`src/components/fonts.css`]
}
}
}
在推送到Gitlab时仍然得到了这个。碰到我的fonts.css时中断。有帮助吗?
11:48:52 AM: build-image version: 84aca9ba39e0ee86ba194760fbfc51a808f62543
11:48:52 AM: buildbot version: 57d44fd1631cc3fff8b38fbaf88d3d04f946418a
11:48:52 AM: Fetching cached dependencies
11:48:52 AM: Failed to fetch cache, continuing with build
11:48:52 AM: Starting to prepare the repo for build
11:48:53 AM: No cached dependencies found. Cloning fresh repo
11:48:53 AM: git clone git@gitlab.com:smallreflection/impossible-possibility
11:48:55 AM: Preparing Git Reference refs/heads/master
11:48:56 AM: Starting build script
11:48:56 AM: Installing dependencies
11:48:57 AM: Downloading and installing node v8.15.0...
11:48:57 AM: Downloading https://nodejs.org/dist/v8.15.0/node-v8.15.0-linux-x64.tar.xz...
11:48:57 AM: 0.0%
11:48:57 AM:
####
11:48:57 AM: 6.9%
11:48:58 AM:
#####################################
11:48:58 AM: 52.5%
11:48:58 AM:
######################################
11:48:58 AM: ################################## 100.0%
11:48:58 AM: Computing checksum with sha256sum
11:48:58 AM: Checksums matched!
11:49:00 AM: Now using node v8.15.0 (npm v6.4.1)
11:49:00 AM: Attempting ruby version 2.3.6, read from environment
11:49:02 AM: Using ruby version 2.3.6
11:49:02 AM: Using PHP version 5.6
11:49:02 AM: Started restoring cached node modules
11:49:02 AM: Finished restoring cached node modules
11:49:02 AM: Installing NPM modules using NPM version 6.4.1
11:49:11 AM: npm
11:49:11 AM: WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
11:50:00 AM: > sharp@0.21.3 install /opt/build/repo/node_modules/sharp
11:50:00 AM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
11:50:00 AM: info
11:50:00 AM: sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.0/libvips-8.7.0-linux-x64.tar.gz
11:50:05 AM: > cwebp-bin@5.0.0 postinstall /opt/build/repo/node_modules/cwebp-bin
11:50:05 AM: > node lib/install.js
11:50:05 AM: ✔ cwebp pre-build test passed successfully
11:50:05 AM: > mozjpeg@6.0.1 postinstall /opt/build/repo/node_modules/mozjpeg
11:50:05 AM: > node lib/install.js
11:50:06 AM: ✔ mozjpeg pre-build test passed successfully
11:50:06 AM: > pngquant-bin@5.0.1 postinstall /opt/build/repo/node_modules/pngquant-bin
11:50:06 AM: > node lib/install.js
11:50:06 AM: ✔ pngquant pre-build test passed successfully
11:50:11 AM: npm notice created a lockfile as package-lock.json. You should commit this file.
11:50:11 AM: npm WARN eslint-config-react-app@3.0.6 requires a peer of eslint@5.x but none is installed. You must install peer dependencies yourself.
11:50:11 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
11:50:11 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:50:11 AM: added 2008 packages from 1192 contributors and audited 24956 packages in 68.565s
11:50:11 AM: found 0 vulnerabilities
11:50:12 AM: NPM modules installed
11:50:12 AM: Started restoring cached go cache
11:50:12 AM: Finished restoring cached go cache
11:50:12 AM: unset GOOS;
11:50:12 AM: unset GOARCH;
11:50:12 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
11:50:12 AM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
11:50:12 AM: go version >&2;
11:50:12 AM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
11:50:12 AM: go version go1.10 linux/amd64
11:50:12 AM: Installing missing commands
11:50:12 AM: Verify run directory
11:50:12 AM: Executing user command: gatsby build
11:50:14 AM: success open and validate gatsby-configs — 0.011 s
11:50:15 AM: success load plugins — 0.334 s
11:50:16 AM: success onPreInit — 1.084 s
11:50:16 AM: success delete html and css files from previous builds — 0.132 s
11:50:16 AM: success initialize cache — 0.014 s
11:50:16 AM: success copy gatsby files — 0.038 s
11:50:16 AM: success onPreBootstrap — 0.006 s
11:50:16 AM: success source and transform nodes — 0.115 s
11:50:17 AM: success building schema — 0.376 s
11:50:17 AM: success createPages — 0.057 s
11:50:17 AM: success createPagesStatefully — 0.040 s
11:50:17 AM: success onPreExtractQueries — 0.004 s
11:50:17 AM: success update schema — 0.190 s
11:50:17 AM: success extract queries from components — 0.147 s
11:50:17 AM: success run graphql queries — 0.176 s — 7/7 40.16 queries/second
11:50:17 AM: success write out page data — 0.003 s
11:50:17 AM: success write out redirect data — 0.001 s
11:50:17 AM: done generating icons for manifest
11:50:17 AM: success onPostBootstrap — 0.099 s
11:50:17 AM: info bootstrap finished - 5.379 s
11:50:31 AM: error Generating JavaScript bundles failed
11:50:31 AM:
11:50:31 AM: Error: ./src/components/fonts.css
11:50:31 AM: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.j s):
11:50:31 AM: ModuleNotFoundError: Module not found: Error: Can't resolve './fonts/boston-we b/Boston-Semibold.woff' in '/opt/build/repo/src/components'
11:50:31 AM: at factory.create (/opt/build/repo/node_modules/webpack/lib/Compilation.js :823:10)
11:50:31 AM: at factory (/opt/build/repo/node_modules/webpack/lib/NormalModuleFactory.j s:397:22)
11:50:31 AM: at resolver (/opt/build/repo/node_modules/webpack/lib/NormalModuleFactory. js:130:21)
11:50:31 AM: at asyncLib.parallel (/opt/build/repo/node_modules/webpack/lib/NormalModul eFactory.js:224:22)
11:50:31 AM: at /opt/build/repo/node_modules/neo-async/async.js:2825:7
11:50:31 AM: at /opt/build/repo/node_modules/neo-async/async.js:6886:13
11:50:31 AM: at normalResolver.resolve (/opt/build/repo/node_modules/webpack/lib/Normal ModuleFactory.js:214:25)
11:50:31 AM: at doResolve (/opt/build/repo/node_modules/enhanced-resolve/lib/Resolver.j s:184:12)
11:50:31 AM: at hook.callAsync (/opt/build/repo/node_modules/enhanced-resolve/lib/Resol ver.js:238:5)
11:50:31 AM: at _fn0 (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCode Factory.js:32:10), <anonymous>:15:1)
11:50:31 AM: at resolver.doResolve (/opt/build/repo/node_modules/enhanced-resolve/lib/U nsafeCachePlugin.js:37:5)
11:50:31 AM: at hook.callAsync (/opt/build/repo/node_modules/enhanced-resolve/lib/Resol ver.js:238:5)
11:50:31 AM: at _fn0 (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCode Factory.js:32:10), <anonymous>:15:1)
11:50:31 AM: at hook.callAsync (/opt/build/repo/node_modules/enhanced-resolve/lib/Resol ver.js:238:5)
11:50:31 AM: at _fn0 (eval at create (/opt/build/repo/node_modules/tapable/lib/HookCode Factory.js:32:10), <anonymous>:12:1)
11:50:31 AM: at resolver.doResolve (/opt/build/repo/node_modules/enhanced-resolve/lib/D escriptionFilePlugin.js:42:38)
11:50:31 AM: @ ./src/components/Layout.js 5:0-21
11:50:31 AM: @ ./src/templates/blog-post.js
11:50:31 AM: @ ./.cache/async-requires.js
11:50:31 AM: @ ./.cache/production-app.js
11:50:31 AM:
11:50:31 AM: Caching artifacts
11:50:31 AM: Started saving node modules
11:50:31 AM: Finished saving node modules
11:50:31 AM: Started saving pip cache
11:50:31 AM: Finished saving pip cache
11:50:31 AM: Started saving emacs cask dependencies
11:50:31 AM: Finished saving emacs cask dependencies
11:50:31 AM: Started saving maven dependencies
11:50:31 AM: Finished saving maven dependencies
11:50:31 AM: Started saving boot dependencies
11:50:31 AM: Finished saving boot dependencies
11:50:31 AM: Started saving go dependencies
11:50:31 AM: Finished saving go dependencies
11:50:32 AM: Cached node version v8.15.0
11:50:32 AM: Error running command: Build script returned non-zero exit code: 1
11:50:32 AM: Failing build: Failed to build site
11:50:32 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
11:50:32 AM: Finished processing build request in 1m39.926023356s
答案 0 :(得分:0)
确保src/components/fonts.css
中的所有路径都是正确的
这些路径应该是src/components
的相对路径,因为这是fonts.css
文件的位置。
其他: 有一些很棒的libraries for the open source fonts可与Gatsby一起使用,以托管自己的字体,而不必自己管理所有资产。此方法不需要Gatsby中的字体加载器。
选择一种字体from the list(例如roboto)
$ yarn add typeface-roboto
import 'typeface-roboto'