Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9349257
fix-swh-source-maps-webpack-plugin.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
fix-swh-source-maps-webpack-plugin.js
View Options
/**
* Copyright (C) 2019 The Software Heritage developers
* See the AUTHORS file at the top-level directory of this distribution
* License: GNU Affero General Public License version 3, or any later version
* See top-level LICENSE file for more information
*/
'use strict'
;
// This plugin modifies the generated asset sourcemaps on the fly
// in order to be successfully loaded by Firefox.
// The following error is reported without that:
// Source map error: TypeError: Invalid URL: webpack://swh.[name]/...
class
FixSwhSourceMapsPlugin
{
constructor
()
{
this
.
sourceMapRegexp
=
/\.map($|\?)/i
;
}
apply
(
compiler
)
{
compiler
.
hooks
.
compilation
.
tap
(
'FixSwhSourceMapsPlugin'
,
compilation
=>
{
const
{
Compilation
,
sources
}
=
require
(
'webpack'
);
compilation
.
hooks
.
processAssets
.
tap
(
{
name
:
'FixSwhSourceMapsPlugin'
,
stage
:
Compilation
.
PROCESS_ASSETS_STAGE_ANALYSE
},
()
=>
{
Object
.
keys
(
compilation
.
assets
).
filter
(
key
=>
{
return
this
.
sourceMapRegexp
.
test
(
key
);
}).
forEach
(
key
=>
{
let
bundleName
=
key
.
replace
(
/^js\//
,
''
);
bundleName
=
bundleName
.
replace
(
/^css\//
,
''
);
const
pos
=
bundleName
.
indexOf
(
'.'
);
bundleName
=
bundleName
.
slice
(
0
,
pos
);
const
asset
=
compilation
.
assets
[
key
];
const
source
=
asset
.
source
().
replace
(
/swh.\[name\]/g
,
'swh.'
+
bundleName
);
compilation
.
updateAsset
(
key
,
new
sources
.
RawSource
(
source
));
});
}
);
});
}
};
module
.
exports
=
FixSwhSourceMapsPlugin
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jul 4 2025, 7:13 PM (6 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3307304
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment