Skip to content

Commit c80b2fa

Browse files
code-asherkylecarbs
authored andcommitted
Use inline file-loader for require.toUrl
Instead of trying to match on the string, because that string could be anything or change in future versions.
1 parent 55f9c81 commit c80b2fa

3 files changed

Lines changed: 28 additions & 49 deletions

File tree

packages/vscode/webpack.config.bootstrap.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,6 @@ module.exports = (env) => {
2727
},
2828
module: {
2929
rules: [{
30-
loader: "string-replace-loader",
31-
test: /\.(js|ts)$/,
32-
options: {
33-
multiple: [
34-
{
35-
search: "require\\.toUrl\\(",
36-
replace: "requireToUrl(",
37-
flags: "g",
38-
},
39-
{
40-
search: "require\\.__\\$__nodeRequire",
41-
replace: "require",
42-
flags: "g",
43-
},
44-
],
45-
},
46-
}, {
4730
// Ignore a bunch of file types we don't have loaders for. Also ignore
4831
// test directories, some files with invalid JSON, and files we don't
4932
// actually require but throw warnings or errors. This all seems to be a

packages/web/webpack.common.config.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ module.exports = merge({
1616
path: path.join(root, "dist"),
1717
filename: "[hash:6].bundle.js",
1818
},
19-
module: {
20-
rules: [{
21-
loader: "string-replace-loader",
22-
test: /\.(j|t)s/,
23-
options: {
24-
multiple: [{
25-
// These will be handled by file-loader. We need the location because
26-
// they are parsed as URIs and will throw errors if not fully formed.
27-
search: "require\\.toUrl",
28-
replace: "location.protocol + '//' + location.host + '/' + require",
29-
flags: "g",
30-
}, {
31-
search: "require\\.__\\$__nodeRequire",
32-
replace: "require",
33-
flags: "g",
34-
}, {
35-
search: "\\.attributes\\[([^\\]]+)\\] = ([^;]+)",
36-
replace: ".setAttribute($1, $2)",
37-
flags: "g",
38-
}],
39-
},
40-
}],
41-
},
4219
node: {
4320
module: "empty",
4421
crypto: "empty",

scripts/webpack.general.config.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ module.exports = (options = {}) => ({
1414
mode: isCi ? "production" : "development",
1515
module: {
1616
rules: [{
17+
loader: "string-replace-loader",
18+
test: /\.(j|t)s/,
19+
options: {
20+
multiple: [{
21+
// These will be handled by file-loader. We need the location because
22+
// they are parsed as URIs and will throw errors if not fully formed.
23+
search: "require\\.toUrl\\(",
24+
replace: "location.protocol + '//' + location.host + '/' + require('file-loader?name=[path][name].[ext]!' + ",
25+
flags: "g",
26+
}, {
27+
search: "require\\.__\\$__nodeRequire",
28+
replace: "require",
29+
flags: "g",
30+
}, {
31+
search: "\\.attributes\\[([^\\]]+)\\] = ([^;]+)",
32+
replace: ".setAttribute($1, $2)",
33+
flags: "g",
34+
}],
35+
},
36+
}, {
1737
test: /\.(js)/,
1838
exclude: /test/,
1939
}, {
@@ -22,12 +42,12 @@ module.exports = (options = {}) => ({
2242
loader: "ignore-loader",
2343
}],
2444
}, {
25-
test: /electron-browser.+\.html$|code\/electron-browser\/.+\.css$|markdown\.css$/,
45+
// These are meant to run in separate pages, like the issue reporter or
46+
// process explorer. Ignoring for now since otherwise their CSS is
47+
// included in the main CSS.
48+
test: /electron-browser.+\.html$|code\/electron-browser\/.+\.css$/,
2649
use: [{
27-
loader: "file-loader",
28-
options: {
29-
name: "[path][name].[ext]",
30-
},
50+
loader: "ignore-loader",
3151
}],
3252
}, {
3353
test: /\.node$/,
@@ -39,9 +59,8 @@ module.exports = (options = {}) => ({
3959
test: /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/,
4060
}, {
4161
// Test CSS isn't required. The rest is supposed to be served in separate
42-
// pages or iframes, so we need to skip it here and serve it with the file
43-
// loader instead.
44-
exclude: /test|code\/electron-browser\/.+\.css|markdown\.css$/,
62+
// pages or iframes so we don't need to include it here.
63+
exclude: /test|code\/electron-browser\/.+\.css$/,
4564
test: /\.s?css$/,
4665
// This is required otherwise it'll fail to resolve CSS in common.
4766
include: root,
@@ -53,7 +72,7 @@ module.exports = (options = {}) => ({
5372
loader: "sass-loader",
5473
}],
5574
}, {
56-
test: /\.(svg|png|ttf|woff|eot|md)$/,
75+
test: /\.(svg|png|ttf|woff|eot)$/,
5776
use: [{
5877
loader: "file-loader",
5978
options: {

0 commit comments

Comments
 (0)