mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 04:34:59 +01:00
Replace dynamic require()s in dependencies with static alternatives
This commit is contained in:
parent
494e208067
commit
31f3ca2ead
@ -42,7 +42,13 @@ void _js({@required bool release}) {
|
||||
// * We thoroughly test edge cases in user input.
|
||||
if (release) ...["-O4", "--fast-startup"]
|
||||
]);
|
||||
var text = destination.readAsStringSync();
|
||||
var text = destination
|
||||
.readAsStringSync()
|
||||
// Some dependencies dynamically invoke `require()`, which makes Webpack
|
||||
// complain. We replace those with direct references to the modules, which
|
||||
// we load explicitly after the preamble.
|
||||
.replaceAllMapped(RegExp(r'self\.require\("([a-zA-Z0-9_-]+)"\)'),
|
||||
(match) => "self.${match[1]}");
|
||||
|
||||
if (release) {
|
||||
// We don't ship the source map, so remove the source map comment.
|
||||
@ -50,10 +56,15 @@ void _js({@required bool release}) {
|
||||
text.replaceFirst(RegExp(r"\n*//# sourceMappingURL=[^\n]+\n*$"), "\n");
|
||||
}
|
||||
|
||||
// Reassigning require() makes Webpack complain.
|
||||
var preambleText =
|
||||
preamble.getPreamble().replaceFirst("self.require = require;\n", "");
|
||||
|
||||
destination.writeAsStringSync("""
|
||||
${preamble.getPreamble()}
|
||||
$preambleText
|
||||
self.fs = require("fs");
|
||||
self.chokidar = require("chokidar");
|
||||
self.readline = require("readline");
|
||||
$text""");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user