Skip to content

Commit 75f0e97

Browse files
committed
webpack 5/laravel-mix 6 support
1 parent 3635fed commit 75f0e97

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AxiosError } from 'axios';
44
import fs = require('fs');
55
const { default: axios } = require('axios'); // Temporary replacement for `import * as axios from 'axios';` while https://github.com/axios/axios/issues/1975 isn't in a release
66
import { flareLog, uuidv4, removeQuery } from './util';
7+
import path = require('path');
78

89
type PluginOptions = {
910
key: string;
@@ -72,7 +73,7 @@ class FlareWebpackPluginSourcemap {
7273
console.error(error);
7374
}
7475

75-
compilation.warnings.push(`@flareapp/flare-webpack-plugin-sourcemap: ${error.message}`);
76+
compilation.warnings.push(`@flareapp/flare-webpack-plugin-sourcemap: ${error.message || error}`);
7677
cb();
7778
});
7879
};
@@ -115,13 +116,11 @@ class FlareWebpackPluginSourcemap {
115116

116117
if (!sourcemaps.length) {
117118
return reject(
118-
`No sourcemap files were found. Make sure sourcemaps are being generated by adding this line to your webpack config: devtool: "hidden-source-map".
119-
If you don't want to upload your sourcemaps to your server, you can add the "removeSourcemaps: true" config option to the Flare webpack plugin.
120-
Laravel Mix' versioning is currently broken with "removeSourcemaps" enabled.`
119+
`No sourcemap files were found. Make sure sourcemaps are being generated by adding this line to your webpack config: devtool: "hidden-source-map". If you don't want to upload your sourcemaps to your server, you can add the "removeSourcemaps: true" config option to the Flare webpack plugin. Laravel Mix' versioning is currently broken with "removeSourcemaps" enabled.`
121120
);
122121
}
123122

124-
Promise.all(sourcemaps.map(sourcemap => this.uploadSourcemap(sourcemap)))
123+
Promise.all(sourcemaps.map((sourcemap) => this.uploadSourcemap(sourcemap)))
125124
.then(() => {
126125
flareLog('Successfully uploaded sourcemaps to Flare.');
127126

@@ -151,11 +150,14 @@ class FlareWebpackPluginSourcemap {
151150
}
152151

153152
return chunks.reduce((sourcemaps, currentChunk) => {
154-
const filename = currentChunk.files.find(file => /\.js/.test(file));
155-
const sourcemapPath = currentChunk.files.find(file => /\.js\.map/.test(file));
153+
const filename = currentChunk.files.find((file) => /\.js/.test(file));
154+
// @ts-expect-error
155+
const sourcemapPath = (currentChunk.auxiliaryFiles || currentChunk.files).find((file) =>
156+
/\.js\.map/.test(file)
157+
);
156158

157159
if (filename && sourcemapPath) {
158-
const sourcemapLocation = removeQuery(compiler.outputFileSystem.join(outputPath, sourcemapPath));
160+
const sourcemapLocation = removeQuery(path.join(outputPath, sourcemapPath));
159161

160162
this.sourcemapPaths.push(sourcemapLocation);
161163

@@ -203,7 +205,7 @@ class FlareWebpackPluginSourcemap {
203205
}
204206

205207
removeAllSourcemaps() {
206-
this.sourcemapPaths.forEach(path => {
208+
this.sourcemapPaths.forEach((path) => {
207209
try {
208210
console.log('removing', path);
209211
fs.unlinkSync(path);

0 commit comments

Comments
 (0)