Skip to content

Commit

Permalink
fix(project-utils): add sourceMappingURL to JS files (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Aug 24, 2023
1 parent 770012a commit b609e37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 12 additions & 2 deletions packages/project-utils/bundling/app/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,19 @@ module.exports = function (webpackEnv, { paths, options }) {
// ** STOP ** Are you adding a new loader?
// Make sure to add the new loader(s) before the "file" loader.
]
}
]
},
shouldUseSourceMap
? {
enforce: "pre",
exclude: /@babel(?:\/|\\{1,2})runtime/,
include: [paths.appSrc, paths.appIndexJs, ...paths.allWorkspaces],
test: /\.js/,
loader: "source-map-loader"
}
: null
].filter(Boolean)
},
ignoreWarnings: [/Failed to parse source map/],
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"]
Expand Down
9 changes: 7 additions & 2 deletions packages/project-utils/packages/buildPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const babelCompile = async ({ cwd }) => {
}
}

// At this point, just wait for compilations to be completed so we can proceed with writing the files ASAP.
// At this point, just wait for compilations to be completed, so we can proceed with writing the files ASAP.
await Promise.all(compilations);

const writes = [];
Expand All @@ -107,7 +107,7 @@ const babelCompile = async ({ cwd }) => {
fs.mkdirSync(dirname(paths.code), { recursive: true });

// Save the compiled JS file.
writes.push(fs.promises.writeFile(paths.code, code, "utf8"));
writes.push(fs.promises.writeFile(paths.code, withSourceMapUrl(file, code), "utf8"));

// Save source maps file.
const mapJson = JSON.stringify(map);
Expand All @@ -118,6 +118,11 @@ const babelCompile = async ({ cwd }) => {
return Promise.all([...writes, ...copies]);
};

const withSourceMapUrl = (file, code) => {
const { name } = parse(file);
return [code, "", `//# sourceMappingURL=${name}.js.map`].join("\n");
};

const tsCompile = ({ cwd, overrides, debug }) => {
return new Promise((resolve, reject) => {
let { config: readTsConfig } = ts.readConfigFile(
Expand Down

0 comments on commit b609e37

Please sign in to comment.