Skip to content

Commit

Permalink
Support jetpack.config.cjs config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz-Kopec committed Dec 28, 2023
1 parent d72e67f commit ae4285e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs-extra')
const path = require('path')
const requireRelative = require('require-relative')

const CONFIG_FILE = 'jetpack.config.js'
const SUPPORTED_CONFIG_FILES = ['jetpack.config.js', 'jetpack.config.cjs']

module.exports = function options(command = 'dev', program = {}) {
const args = program.args || []
Expand All @@ -25,7 +25,9 @@ module.exports = function options(command = 'dev', program = {}) {
process.env.NODE_ENV = 'production'
}

const configFromFile = readConfigFromFile(dir, opts.config || CONFIG_FILE)
const configPath = opts.config || SUPPORTED_CONFIG_FILES.find((file) => fs.pathExistsSync(path.join(dir, file)))

const configFromFile = readConfigFromFile(dir, configPath)
const options = Object.assign(
{},
configFromFile,
Expand Down Expand Up @@ -105,8 +107,8 @@ module.exports = function options(command = 'dev', program = {}) {
? undefined
: 'source-map'
: options.sourceMaps === true
? 'source-map'
: options.sourceMaps,
? 'source-map'
: options.sourceMaps,

// to turn off minification in production
minify: options.minify === undefined ? true : options.minify,
Expand Down Expand Up @@ -184,6 +186,7 @@ function clean(obj) {
}

function readConfigFromFile(dir, configFilePath) {
if (!configFilePath) return {}
const configPath = path.join(dir, configFilePath)
const exists = fs.pathExistsSync(configPath)
return exists ? require(configPath) : {}
Expand Down

0 comments on commit ae4285e

Please sign in to comment.