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.
This commit is contained in:
parent
55f9c81516
commit
c80b2fabc3
@ -27,23 +27,6 @@ module.exports = (env) => {
|
|||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
loader: "string-replace-loader",
|
|
||||||
test: /\.(js|ts)$/,
|
|
||||||
options: {
|
|
||||||
multiple: [
|
|
||||||
{
|
|
||||||
search: "require\\.toUrl\\(",
|
|
||||||
replace: "requireToUrl(",
|
|
||||||
flags: "g",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
search: "require\\.__\\$__nodeRequire",
|
|
||||||
replace: "require",
|
|
||||||
flags: "g",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
// Ignore a bunch of file types we don't have loaders for. Also ignore
|
// Ignore a bunch of file types we don't have loaders for. Also ignore
|
||||||
// test directories, some files with invalid JSON, and files we don't
|
// test directories, some files with invalid JSON, and files we don't
|
||||||
// actually require but throw warnings or errors. This all seems to be a
|
// actually require but throw warnings or errors. This all seems to be a
|
||||||
|
@ -16,29 +16,6 @@ module.exports = merge({
|
|||||||
path: path.join(root, "dist"),
|
path: path.join(root, "dist"),
|
||||||
filename: "[hash:6].bundle.js",
|
filename: "[hash:6].bundle.js",
|
||||||
},
|
},
|
||||||
module: {
|
|
||||||
rules: [{
|
|
||||||
loader: "string-replace-loader",
|
|
||||||
test: /\.(j|t)s/,
|
|
||||||
options: {
|
|
||||||
multiple: [{
|
|
||||||
// These will be handled by file-loader. We need the location because
|
|
||||||
// they are parsed as URIs and will throw errors if not fully formed.
|
|
||||||
search: "require\\.toUrl",
|
|
||||||
replace: "location.protocol + '//' + location.host + '/' + require",
|
|
||||||
flags: "g",
|
|
||||||
}, {
|
|
||||||
search: "require\\.__\\$__nodeRequire",
|
|
||||||
replace: "require",
|
|
||||||
flags: "g",
|
|
||||||
}, {
|
|
||||||
search: "\\.attributes\\[([^\\]]+)\\] = ([^;]+)",
|
|
||||||
replace: ".setAttribute($1, $2)",
|
|
||||||
flags: "g",
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
node: {
|
node: {
|
||||||
module: "empty",
|
module: "empty",
|
||||||
crypto: "empty",
|
crypto: "empty",
|
||||||
|
@ -14,6 +14,26 @@ module.exports = (options = {}) => ({
|
|||||||
mode: isCi ? "production" : "development",
|
mode: isCi ? "production" : "development",
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
|
loader: "string-replace-loader",
|
||||||
|
test: /\.(j|t)s/,
|
||||||
|
options: {
|
||||||
|
multiple: [{
|
||||||
|
// These will be handled by file-loader. We need the location because
|
||||||
|
// they are parsed as URIs and will throw errors if not fully formed.
|
||||||
|
search: "require\\.toUrl\\(",
|
||||||
|
replace: "location.protocol + '//' + location.host + '/' + require('file-loader?name=[path][name].[ext]!' + ",
|
||||||
|
flags: "g",
|
||||||
|
}, {
|
||||||
|
search: "require\\.__\\$__nodeRequire",
|
||||||
|
replace: "require",
|
||||||
|
flags: "g",
|
||||||
|
}, {
|
||||||
|
search: "\\.attributes\\[([^\\]]+)\\] = ([^;]+)",
|
||||||
|
replace: ".setAttribute($1, $2)",
|
||||||
|
flags: "g",
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}, {
|
||||||
test: /\.(js)/,
|
test: /\.(js)/,
|
||||||
exclude: /test/,
|
exclude: /test/,
|
||||||
}, {
|
}, {
|
||||||
@ -22,12 +42,12 @@ module.exports = (options = {}) => ({
|
|||||||
loader: "ignore-loader",
|
loader: "ignore-loader",
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
test: /electron-browser.+\.html$|code\/electron-browser\/.+\.css$|markdown\.css$/,
|
// These are meant to run in separate pages, like the issue reporter or
|
||||||
|
// process explorer. Ignoring for now since otherwise their CSS is
|
||||||
|
// included in the main CSS.
|
||||||
|
test: /electron-browser.+\.html$|code\/electron-browser\/.+\.css$/,
|
||||||
use: [{
|
use: [{
|
||||||
loader: "file-loader",
|
loader: "ignore-loader",
|
||||||
options: {
|
|
||||||
name: "[path][name].[ext]",
|
|
||||||
},
|
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
@ -39,9 +59,8 @@ module.exports = (options = {}) => ({
|
|||||||
test: /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/,
|
test: /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/,
|
||||||
}, {
|
}, {
|
||||||
// Test CSS isn't required. The rest is supposed to be served in separate
|
// Test CSS isn't required. The rest is supposed to be served in separate
|
||||||
// pages or iframes, so we need to skip it here and serve it with the file
|
// pages or iframes so we don't need to include it here.
|
||||||
// loader instead.
|
exclude: /test|code\/electron-browser\/.+\.css$/,
|
||||||
exclude: /test|code\/electron-browser\/.+\.css|markdown\.css$/,
|
|
||||||
test: /\.s?css$/,
|
test: /\.s?css$/,
|
||||||
// This is required otherwise it'll fail to resolve CSS in common.
|
// This is required otherwise it'll fail to resolve CSS in common.
|
||||||
include: root,
|
include: root,
|
||||||
@ -53,7 +72,7 @@ module.exports = (options = {}) => ({
|
|||||||
loader: "sass-loader",
|
loader: "sass-loader",
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
test: /\.(svg|png|ttf|woff|eot|md)$/,
|
test: /\.(svg|png|ttf|woff|eot)$/,
|
||||||
use: [{
|
use: [{
|
||||||
loader: "file-loader",
|
loader: "file-loader",
|
||||||
options: {
|
options: {
|
||||||
|
Reference in New Issue
Block a user