mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(cli): rebuild if process.env changes in nuxt.config (#8200)
This commit is contained in:
parent
5842a64506
commit
d9f48228fe
@ -59,13 +59,27 @@ export async function ensureBuild (cmd) {
|
|||||||
|
|
||||||
const currentBuildSnapshot = await snapshot(snapshotOptions)
|
const currentBuildSnapshot = await snapshot(snapshotOptions)
|
||||||
|
|
||||||
|
// Detect process.env usage in nuxt.config
|
||||||
|
const processEnv = {}
|
||||||
|
if (nuxt.options._nuxtConfigFile) {
|
||||||
|
const configSrc = await fs.readFile(nuxt.options._nuxtConfigFile)
|
||||||
|
const envRegex = /process.env.(\w+)/g
|
||||||
|
let match
|
||||||
|
// eslint-disable-next-line no-cond-assign
|
||||||
|
while (match = envRegex.exec(configSrc)) {
|
||||||
|
processEnv[match[1]] = process.env[match[1]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Current build meta
|
// Current build meta
|
||||||
const currentBuild = {
|
const currentBuild = {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
nuxtVersion: nuxt.constructor.version,
|
nuxtVersion: nuxt.constructor.version,
|
||||||
ssr: nuxt.options.ssr,
|
ssr: nuxt.options.ssr,
|
||||||
target: nuxt.options.target,
|
target: nuxt.options.target,
|
||||||
snapshot: currentBuildSnapshot
|
snapshot: currentBuildSnapshot,
|
||||||
|
env: nuxt.options.env,
|
||||||
|
'process.env': processEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if build can be skipped
|
// Check if build can be skipped
|
||||||
@ -74,9 +88,10 @@ export async function ensureBuild (cmd) {
|
|||||||
const previousBuild = destr(fs.readFileSync(nuxtBuildFile, 'utf-8')) || {}
|
const previousBuild = destr(fs.readFileSync(nuxtBuildFile, 'utf-8')) || {}
|
||||||
|
|
||||||
// Quick diff
|
// Quick diff
|
||||||
const needBuild = false
|
let needBuild = false
|
||||||
for (const field of ['nuxtVersion', 'ssr', 'target']) {
|
for (const field of ['nuxtVersion', 'ssr', 'target', 'env', 'process.env']) {
|
||||||
if (previousBuild[field] !== currentBuild[field]) {
|
if (JSON.stringify(previousBuild[field]) !== JSON.stringify(currentBuild[field])) {
|
||||||
|
needBuild = true
|
||||||
consola.info(`Doing webpack rebuild because ${field} changed`)
|
consola.info(`Doing webpack rebuild because ${field} changed`)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
6
test/fixtures/full-static/nuxt.config.js
vendored
6
test/fixtures/full-static/nuxt.config.js
vendored
@ -11,6 +11,12 @@ export default {
|
|||||||
build: {
|
build: {
|
||||||
publicPath: '/test/_nuxt/'
|
publicPath: '/test/_nuxt/'
|
||||||
},
|
},
|
||||||
|
foo: {
|
||||||
|
shell: process.env.SHELL
|
||||||
|
},
|
||||||
|
env: {
|
||||||
|
x: 123
|
||||||
|
},
|
||||||
hooks: {
|
hooks: {
|
||||||
export: {
|
export: {
|
||||||
before ({ setPayload }) {
|
before ({ setPayload }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user