Skip to content

Commit

Permalink
chore: add sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiQiangReal committed Jul 9, 2024
1 parent bfe3843 commit 340afa8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ exports.onPostBuild = async () => {

(()=>{
const jsFiles = glob.sync(`${publicPath}/*.js`);

const mapFiles = glob.sync(`${publicPath}/*.map`);
const replaceNames = {};

for (let file of jsFiles) {
const filename = path.basename(file);
const fileNameWithoutExt = filename.split('.')[0];
Expand All @@ -392,6 +393,25 @@ exports.onPostBuild = async () => {
fs.renameSync(file, path.join(path.dirname(file), finalFileName));
}
}

for (let file of mapFiles) {
const filename = path.basename(file);
const fileNameWithoutExt = filename.split('.')[0];
const originHash = fileNameWithoutExt.split('-').at(-1);

if (originHash && originHash!==fileNameWithoutExt) {
let fileNameWithoutExtWithHash = fileNameWithoutExt.replace(originHash, `${originHash}${numHash}`);
replaceNames[originHash] = `${originHash}${numHash}`;
fs.renameSync(file, path.join(path.dirname(file), `${fileNameWithoutExtWithHash}.js.map`));
} else {
let finalFileName = `${fileNameWithoutExt}${numHash}.js.map`;
replaceNames[filename] = finalFileName;
fs.renameSync(file, path.join(path.dirname(file), finalFileName));
}
}



const allFiles = glob.sync(`${publicPath}/**/*.{js,html,json}`);
for (let file of allFiles) {
const stats = fs.statSync(file);
Expand Down

0 comments on commit 340afa8

Please sign in to comment.