mirror of https://github.com/webpack/webpack.git
handle more cases with an regexp
This commit is contained in:
parent
d575996433
commit
bd35396503
|
@ -704,11 +704,8 @@ const applyOutputDefaults = (
|
|||
"type" in library
|
||||
? library.name
|
||||
: /** @type {LibraryName=} */ (library);
|
||||
const excludePlaceholders = ["[name]"];
|
||||
if (Array.isArray(libraryName)) {
|
||||
return libraryName
|
||||
.filter(item => !excludePlaceholders.includes(item))
|
||||
.join(".");
|
||||
return libraryName.join(".");
|
||||
} else if (typeof libraryName === "object") {
|
||||
return getLibraryName(libraryName.root);
|
||||
} else if (typeof libraryName === "string") {
|
||||
|
@ -718,7 +715,15 @@ const applyOutputDefaults = (
|
|||
};
|
||||
|
||||
F(output, "uniqueName", () => {
|
||||
const libraryName = getLibraryName(output.library);
|
||||
const libraryName = getLibraryName(output.library).replace(
|
||||
/^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g,
|
||||
(m, a, d1, d2, b, c) => {
|
||||
const content = a || b || c;
|
||||
return content.startsWith("\\") && content.endsWith("\\")
|
||||
? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
|
||||
: "";
|
||||
}
|
||||
);
|
||||
if (libraryName) return libraryName;
|
||||
const pkgPath = path.resolve(context, "package.json");
|
||||
try {
|
||||
|
|
|
@ -1102,7 +1102,7 @@ describe("Defaults", () => {
|
|||
{
|
||||
output: {
|
||||
library: {
|
||||
name: ["myLib", "[name]"],
|
||||
name: ["my[name]Lib", "[name]", "lib"],
|
||||
type: "var"
|
||||
}
|
||||
}
|
||||
|
@ -1114,10 +1114,10 @@ describe("Defaults", () => {
|
|||
|
||||
@@ ... @@
|
||||
- "chunkLoadingGlobal": "webpackChunkwebpack",
|
||||
+ "chunkLoadingGlobal": "webpackChunkmyLib",
|
||||
+ "chunkLoadingGlobal": "webpackChunkmyLib_lib",
|
||||
@@ ... @@
|
||||
- "devtoolNamespace": "webpack",
|
||||
+ "devtoolNamespace": "myLib",
|
||||
+ "devtoolNamespace": "myLib.lib",
|
||||
@@ ... @@
|
||||
- "enabledLibraryTypes": Array [],
|
||||
+ "enabledLibraryTypes": Array [
|
||||
|
@ -1125,22 +1125,23 @@ describe("Defaults", () => {
|
|||
+ ],
|
||||
@@ ... @@
|
||||
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdatemyLib",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdatemyLib_lib",
|
||||
@@ ... @@
|
||||
- "library": undefined,
|
||||
+ "library": Object {
|
||||
+ "auxiliaryComment": undefined,
|
||||
+ "export": undefined,
|
||||
+ "name": Array [
|
||||
+ "myLib",
|
||||
+ "my[name]Lib",
|
||||
+ "[name]",
|
||||
+ "lib",
|
||||
+ ],
|
||||
+ "type": "var",
|
||||
+ "umdNamedDefine": undefined,
|
||||
+ },
|
||||
@@ ... @@
|
||||
- "uniqueName": "webpack",
|
||||
+ "uniqueName": "myLib",
|
||||
+ "uniqueName": "myLib.lib",
|
||||
`)
|
||||
);
|
||||
test(
|
||||
|
@ -1149,7 +1150,7 @@ describe("Defaults", () => {
|
|||
output: {
|
||||
library: {
|
||||
name: {
|
||||
root: ["myLib", "[name]"]
|
||||
root: ["[name]", "myLib"]
|
||||
},
|
||||
type: "var"
|
||||
}
|
||||
|
@ -1181,8 +1182,8 @@ describe("Defaults", () => {
|
|||
+ "export": undefined,
|
||||
+ "name": Object {
|
||||
+ "root": Array [
|
||||
+ "myLib",
|
||||
+ "[name]",
|
||||
+ "myLib",
|
||||
+ ],
|
||||
+ },
|
||||
+ "type": "var",
|
||||
|
@ -1193,6 +1194,57 @@ describe("Defaults", () => {
|
|||
+ "uniqueName": "myLib",
|
||||
`)
|
||||
);
|
||||
test(
|
||||
"library.name.root contains escaped placeholder",
|
||||
{
|
||||
output: {
|
||||
library: {
|
||||
name: {
|
||||
root: ["[\\name\\]", "my[\\name\\]Lib[name]", "[\\name\\]"]
|
||||
},
|
||||
type: "var"
|
||||
}
|
||||
}
|
||||
},
|
||||
e =>
|
||||
e.toMatchInlineSnapshot(`
|
||||
- Expected
|
||||
+ Received
|
||||
|
||||
@@ ... @@
|
||||
- "chunkLoadingGlobal": "webpackChunkwebpack",
|
||||
+ "chunkLoadingGlobal": "webpackChunk_name_my_name_Lib_name_",
|
||||
@@ ... @@
|
||||
- "devtoolNamespace": "webpack",
|
||||
+ "devtoolNamespace": "[name].my[name]Lib.[name]",
|
||||
@@ ... @@
|
||||
- "enabledLibraryTypes": Array [],
|
||||
+ "enabledLibraryTypes": Array [
|
||||
+ "var",
|
||||
+ ],
|
||||
@@ ... @@
|
||||
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdate_name_my_name_Lib_name_",
|
||||
@@ ... @@
|
||||
- "library": undefined,
|
||||
+ "library": Object {
|
||||
+ "auxiliaryComment": undefined,
|
||||
+ "export": undefined,
|
||||
+ "name": Object {
|
||||
+ "root": Array [
|
||||
+ "[\\\\name\\\\]",
|
||||
+ "my[\\\\name\\\\]Lib[name]",
|
||||
+ "[\\\\name\\\\]",
|
||||
+ ],
|
||||
+ },
|
||||
+ "type": "var",
|
||||
+ "umdNamedDefine": undefined,
|
||||
+ },
|
||||
@@ ... @@
|
||||
- "uniqueName": "webpack",
|
||||
+ "uniqueName": "[name].my[name]Lib.[name]",
|
||||
`)
|
||||
);
|
||||
test("target node", { target: "node" }, e =>
|
||||
e.toMatchInlineSnapshot(`
|
||||
- Expected
|
||||
|
|
Loading…
Reference in New Issue