Skip to content

Commit

Permalink
moving prod sourcemap to separate files, fix #319
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv committed Dec 15, 2022
1 parent f9e11b0 commit ba1d2a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 1 addition & 2 deletions cli/plasmo/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const commonConfig = {
async function main() {
const config = await fse.readJson("package.json")
const define = {
"process.env.APP_VERSION": `"${config.version}"`,
"process.env.LAB": watch
"process.env.APP_VERSION": `"${config.version}"`
}

await build({
Expand Down
17 changes: 13 additions & 4 deletions cli/plasmo/src/features/helpers/create-parcel-bundler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Parcel } from "@parcel/core"
import ParcelFS from "@parcel/fs"
import ParcelPM from "@parcel/package-manager"
import { emptyDir, readJson } from "fs-extra"
import { resolve } from "path"
import { emptyDir, readJson, writeJson } from "fs-extra"
import { dirname, join, resolve } from "path"

import { hasFlag } from "@plasmo/utils/flags"

import type { CommonPath } from "~features/extension-devtools/common-path"

Expand Down Expand Up @@ -35,16 +37,23 @@ export const createParcelBuilder = async (
)

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

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

const configJson = await readJson(baseConfig)

console.log(configJson)
if (hasFlag("--bundle-buddy")) {
configJson.reporters = ["...", "@parcel/reporter-bundle-buddy"]
}

await writeJson(runConfig, configJson)

const bundler = new Parcel({
inputFS,
packageManager,
entries: commonPath.entryManifestPath,
cacheDir: resolve(commonPath.cacheDirectory, "parcel"),
config: require.resolve("@plasmohq/parcel-config"),
config: runConfig,
shouldAutoInstall: true,
...options
})
Expand Down
1 change: 1 addition & 0 deletions packages/parcel-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run.json
16 changes: 14 additions & 2 deletions packages/parcel-transformer-manifest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import { parse } from "@mischnic/json-sourcemap"
import { Transformer } from "@parcel/plugin"
import type { TargetSourceMapOptions } from "@parcel/types"
import { validateSchema } from "@parcel/utils"

import { vLog } from "@plasmo/utils/logging"
Expand Down Expand Up @@ -46,6 +47,18 @@ export default new Transformer({
vLog("@plasmohq/parcel-transformer-manifest")
// Set environment to browser, since web extensions are always used in
// browsers, and because it avoids delegating extra config to the user

const sourceMapConfig: TargetSourceMapOptions =
options.mode === "development"
? {
inline: true,
inlineSources: true
}
: {
inline: false,
inlineSources: false
}

asset.setEnvironment({
context: "browser",
outputFormat:
Expand All @@ -57,8 +70,7 @@ export default new Transformer({
},
sourceMap: asset.env.sourceMap && {
...asset.env.sourceMap,
inline: true,
inlineSources: true
...sourceMapConfig
},
includeNodeModules: asset.env.includeNodeModules,
sourceType: asset.env.sourceType,
Expand Down

0 comments on commit ba1d2a9

Please sign in to comment.