Skip to content

Commit da4f80f

Browse files
rexxarsbjoerge
authored andcommitted
[webpack-loader] Reduce configs based on webpack environment (#553)
1 parent b50bc41 commit da4f80f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/@sanity/webpack-loader/src/partLoader.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const env = typeof sanityEnv === 'undefined' ? process.env.NODE_ENV : sanityEnv
1515
function sanityPartLoader(input) {
1616
this.cacheable()
1717

18+
let buildEnv = sanityEnv
19+
if (!buildEnv) {
20+
buildEnv = this.options.devtool ? env : 'production'
21+
}
22+
1823
const qs = this.resourceQuery.substring(this.resourceQuery.indexOf('?'))
1924
const request = (loaderUtils.parseQuery(qs) || {}).sanityPart
2025

@@ -31,14 +36,14 @@ function sanityPartLoader(input) {
3136

3237
if (request.indexOf('config:') === 0) {
3338
const config = JSON.parse(input)
34-
const indent = env === 'production' ? 0 : 2
35-
const reduced = reduceConfig(config, env)
39+
const indent = buildEnv === 'production' ? 0 : 2
40+
const reduced = reduceConfig(config, buildEnv)
3641
return `module.exports = ${JSON.stringify(reduced, null, indent)}\n`
3742
}
3843

3944
if (request === 'sanity:versions') {
4045
const versions = getSanityVersions(basePath)
41-
const indent = env === 'production' ? 0 : 2
46+
const indent = buildEnv === 'production' ? 0 : 2
4247
return `module.exports = ${JSON.stringify(versions, null, indent)}\n`
4348
}
4449

0 commit comments

Comments
 (0)