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

feat: Support custom .parcelrc config #890

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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
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
Loading