mirror of https://github.com/webpack/webpack.git
Compare commits
6 Commits
b8b334c3eb
...
433bcc39ef
Author | SHA1 | Date |
---|---|---|
|
433bcc39ef | |
|
11144e4eec | |
|
4abdfa94df | |
|
4587dbb336 | |
|
c056283928 | |
|
5604ce9b89 |
|
@ -5,11 +5,11 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Include source maps for modules based on their extension (defaults to .js and .css).
|
||||
* One or multiple conditions used to match resource.
|
||||
*/
|
||||
export type Rules = Rule[] | Rule;
|
||||
/**
|
||||
* Include source maps for modules based on their extension (defaults to .js and .css).
|
||||
* Condition used to match resource (string, RegExp or Function).
|
||||
*/
|
||||
export type Rule = RegExp | string | ((str: string) => boolean);
|
||||
|
||||
|
@ -47,6 +47,10 @@ export interface SourceMapDevToolPluginOptions {
|
|||
* Defines the output filename of the SourceMap (will be inlined if no value is provided).
|
||||
*/
|
||||
filename?: (false | null) | string;
|
||||
/**
|
||||
* Decide whether to ignore source files that match the specified value in the SourceMap.
|
||||
*/
|
||||
ignoreList?: Rules;
|
||||
/**
|
||||
* Include source maps for module paths that match the given value.
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|||
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
|
||||
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
|
@ -163,6 +164,21 @@ class EvalSourceMapDevToolPlugin {
|
|||
}
|
||||
);
|
||||
sourceMap.sources = moduleFilenames;
|
||||
sourceMap.ignoreList = options.ignoreList
|
||||
? sourceMap.sources.reduce(
|
||||
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
|
||||
(acc, sourceName, idx) => {
|
||||
const rule = /** @type {Rules} */ (options.ignoreList);
|
||||
if (ModuleFilenameHelpers.matchPart(sourceName, rule)) {
|
||||
acc.push(idx);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
),
|
||||
[]
|
||||
)
|
||||
: [];
|
||||
|
||||
if (options.noSources) {
|
||||
sourceMap.sourcesContent = undefined;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|||
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
|
||||
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Compilation").Asset} Asset */
|
||||
|
@ -433,6 +434,25 @@ class SourceMapDevToolPlugin {
|
|||
moduleToSourceNameMapping.get(m)
|
||||
);
|
||||
sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
|
||||
sourceMap.ignoreList = options.ignoreList
|
||||
? sourceMap.sources.reduce(
|
||||
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
|
||||
(acc, sourceName, idx) => {
|
||||
const rule = /** @type {Rules} */ (
|
||||
options.ignoreList
|
||||
);
|
||||
if (
|
||||
ModuleFilenameHelpers.matchPart(sourceName, rule)
|
||||
) {
|
||||
acc.push(idx);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
),
|
||||
[]
|
||||
)
|
||||
: [];
|
||||
|
||||
if (options.noSources) {
|
||||
sourceMap.sourcesContent = undefined;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
if (options && options.baseUri) {
|
||||
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
||||
}
|
||||
return `${RuntimeGlobals.baseURI} = (document && document.baseURI) || self.location.href;`;
|
||||
return `${RuntimeGlobals.baseURI} = (typeof document !== 'undefined' && document.baseURI) || self.location.href;`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"definitions": {
|
||||
"rule": {
|
||||
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
|
||||
"description": "Condition used to match resource (string, RegExp or Function).",
|
||||
"anyOf": [
|
||||
{
|
||||
"instanceof": "RegExp",
|
||||
|
@ -18,7 +18,7 @@
|
|||
]
|
||||
},
|
||||
"rules": {
|
||||
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
|
||||
"description": "One or multiple conditions used to match resource.",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "array",
|
||||
|
@ -106,6 +106,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"ignoreList": {
|
||||
"description": "Decide whether to ignore source files that match the specified value in the SourceMap.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/rules"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": {
|
||||
"description": "Include source maps for module paths that match the given value.",
|
||||
"oneOf": [
|
||||
|
@ -149,7 +157,12 @@
|
|||
"type": "string"
|
||||
},
|
||||
"test": {
|
||||
"$ref": "#/definitions/rules"
|
||||
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/rules"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export default "ignored";
|
|
@ -0,0 +1,34 @@
|
|||
import used from "./used";
|
||||
import ignored from "./ignored";
|
||||
import fs from "fs";
|
||||
|
||||
const getSourceMap = () => {
|
||||
const source = fs.readFileSync(__filename, "utf-8");
|
||||
const match =
|
||||
/\/\/# sourceMappingURL\s*=\s*data:application\/json;charset=utf-8;base64,(.*)\\n\/\/#/.exec(
|
||||
source
|
||||
);
|
||||
const mapString = Buffer.from(match[1], "base64").toString("utf-8");
|
||||
return JSON.parse(mapString);
|
||||
};
|
||||
|
||||
const map = getSourceMap();
|
||||
|
||||
it("marks matching modules in ignoreList", () => {
|
||||
const sources = map.sources;
|
||||
const ignoredIndex = sources.findIndex((source) =>
|
||||
/ignored\.js/.test(source)
|
||||
);
|
||||
expect(ignored).toBe("ignored");
|
||||
expect(ignoredIndex).not.toBe(-1);
|
||||
expect(Array.isArray(map.ignoreList)).toBe(true);
|
||||
expect(map.ignoreList).toContain(ignoredIndex);
|
||||
});
|
||||
|
||||
it("keeps other modules outside ignoreList", () => {
|
||||
const sources = map.sources;
|
||||
const usedIndex = sources.findIndex((source) => /used\.js/.test(source));
|
||||
expect(used).toBe("used");
|
||||
expect(usedIndex).not.toBe(-1);
|
||||
expect(map.ignoreList).not.toContain(usedIndex);
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
export default "used";
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
devtool: false,
|
||||
plugins: [
|
||||
new webpack.EvalSourceMapDevToolPlugin({
|
||||
ignoreList: [/ignored\.js/]
|
||||
})
|
||||
],
|
||||
optimization: {
|
||||
// Ensure the correct `sourceMappingURL` is detected
|
||||
concatenateModules: true
|
||||
}
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
export default "ignored";
|
|
@ -0,0 +1,33 @@
|
|||
import used from "./used";
|
||||
import ignored from "./ignored";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const getSourceMap = () => {
|
||||
const content = fs.readFileSync(
|
||||
path.join(__dirname, "bundle0.js.map"),
|
||||
"utf-8"
|
||||
);
|
||||
return JSON.parse(content);
|
||||
};
|
||||
|
||||
const map = getSourceMap();
|
||||
|
||||
it("marks matching modules in ignoreList", () => {
|
||||
const sources = map.sources;
|
||||
const ignoredIndex = sources.findIndex((source) =>
|
||||
/ignored\.js/.test(source)
|
||||
);
|
||||
expect(ignored).toBe("ignored");
|
||||
expect(ignoredIndex).not.toBe(-1);
|
||||
expect(Array.isArray(map.ignoreList)).toBe(true);
|
||||
expect(map.ignoreList).toContain(ignoredIndex);
|
||||
});
|
||||
|
||||
it("keeps other modules outside ignoreList", () => {
|
||||
const sources = map.sources;
|
||||
const usedIndex = sources.findIndex((source) => /used\.js/.test(source));
|
||||
expect(used).toBe("used");
|
||||
expect(usedIndex).not.toBe(-1);
|
||||
expect(map.ignoreList).not.toContain(usedIndex);
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
export default "used";
|
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
devtool: false,
|
||||
plugins: [
|
||||
new webpack.SourceMapDevToolPlugin({
|
||||
filename: "[file].map",
|
||||
ignoreList: [/ignored\.js/]
|
||||
})
|
||||
]
|
||||
};
|
|
@ -16513,6 +16513,11 @@ declare interface SourceMapDevToolPluginOptions {
|
|||
*/
|
||||
filename?: null | string | false;
|
||||
|
||||
/**
|
||||
* Decide whether to ignore source files that match the specified value in the SourceMap.
|
||||
*/
|
||||
ignoreList?: string | RegExp | Rule[] | ((str: string) => boolean);
|
||||
|
||||
/**
|
||||
* Include source maps for module paths that match the given value.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue