Skip to content

Commit

Permalink
feat: Support custom .parcelrc config (#890)
Browse files Browse the repository at this point in the history
Co-authored-by: L <[email protected]>
  • Loading branch information
mathieudutour and louisgv authored Mar 7, 2024
1 parent e1047bd commit 748ad28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/plasmo/src/features/extension-devtools/common-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const getCommonPath = (projectDirectory = cwd()) => {
packageFilePath: resolve(projectDirectory, "package.json"),
gitIgnorePath: resolve(projectDirectory, ".gitignore"),
assetsDirectory: resolve(projectDirectory, "assets"),
parcelConfig: resolve(projectDirectory, ".parcelrc"),

dotPlasmoDirectory,
cacheDirectory,
Expand Down
25 changes: 23 additions & 2 deletions cli/plasmo/src/features/helpers/create-parcel-bundler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { dirname, join, resolve } from "path"
import ParcelFS from "@parcel/fs"
import ParcelPM from "@parcel/package-manager"
import { emptyDir, ensureDir, readJson, writeJson } from "fs-extra"
import { emptyDir, ensureDir, exists, readJson, writeJson } from "fs-extra"

import { getFlag, hasFlag } from "@plasmo/utils/flags"
import { wLog } from "@plasmo/utils/logging"

import { Parcel, type ParcelOptions } from "@plasmohq/parcel-core"

Expand Down Expand Up @@ -65,7 +66,7 @@ export const createParcelBuilder = async (

const baseConfig = require.resolve("@plasmohq/parcel-config")

const runConfig = join(dirname(baseConfig), "run.json")
let runConfig = join(dirname(baseConfig), "run.json")

const configJson = await readJson(baseConfig)

Expand All @@ -75,6 +76,26 @@ export const createParcelBuilder = async (

await writeJson(runConfig, configJson)

if (await exists(commonPath.parcelConfig)) {
runConfig = commonPath.parcelConfig

if (isProd) {
const customConfig = await readJson(runConfig)

if (customConfig.extends !== "@plasmohq/parcel-config") {
wLog(
'The .parcelrc does not extend "@plasmohq/parcel-config", the result may be unexpected'
)
}
}

if (hasFlag("--bundle-buddy")) {
wLog(
'The "--bundle-buddy" flag does not work with a custom .parcelrc file'
)
}
}

const engines = {
browsers:
bundleConfig.manifestVersion === "mv2" &&
Expand Down

0 comments on commit 748ad28

Please sign in to comment.