Skip to content

Commit

Permalink
fix: read sanity.json at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 21, 2020
1 parent 598c4e2 commit b3e804f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -44,6 +44,7 @@
"@nuxtjs/tailwindcss": "^3.0.0",
"@release-it/conventional-changelog": "^1.1.4",
"@sanity/client": "^1.149.18",
"@types/fs-extra": "^9.0.1",
"@types/jest": "latest",
"@types/webpack-env": "^1.15.2",
"@vue/test-utils": "^1.0.3",
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
Expand Up @@ -72,13 +72,11 @@ const nuxtModule: Module<SanityModuleOptions> = function (moduleOptions) {

try {
// eslint-disable-next-line
if (process.server) {
const fs = require('fs-extra')
const { projectId, dataset } = fs.readJSONSync(
resolve(this.options.rootDir, './sanity.json'),
).api
sanityConfig = { projectId, dataset }
}
const fs: typeof import('fs-extra') = process.client ? {} : require('fs-extra')
const { projectId, dataset } = fs.readJSONSync(
resolve(this.options.rootDir, './sanity.json'),
).api
sanityConfig = { projectId, dataset }
} catch {}

const options = defu<SanityModuleOptions>(
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Expand Up @@ -1942,6 +1942,13 @@
dependencies:
"@types/webpack" "*"

"@types/fs-extra@^9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.1.tgz#91c8fc4c51f6d5dbe44c2ca9ab09310bd00c7918"
integrity sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg==
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
Expand Down

0 comments on commit b3e804f

Please sign in to comment.