Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support jetpack.config.cjs config file #118

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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