commit
f43047c4c2
|
@ -715,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 {
|
||||
|
|
|
@ -1060,6 +1060,197 @@ describe("snapshots", () => {
|
|||
+ "uniqueName": "myLib.awesome",
|
||||
`)
|
||||
);
|
||||
test(
|
||||
"library contains [name] placeholder",
|
||||
{
|
||||
output: {
|
||||
library: ["myLib", "[name]"]
|
||||
}
|
||||
},
|
||||
e =>
|
||||
e.toMatchInlineSnapshot(`
|
||||
- Expected
|
||||
+ Received
|
||||
|
||||
@@ ... @@
|
||||
- "chunkLoadingGlobal": "webpackChunkwebpack",
|
||||
+ "chunkLoadingGlobal": "webpackChunkmyLib",
|
||||
@@ ... @@
|
||||
- "devtoolNamespace": "webpack",
|
||||
+ "devtoolNamespace": "myLib",
|
||||
@@ ... @@
|
||||
- "enabledLibraryTypes": Array [],
|
||||
+ "enabledLibraryTypes": Array [
|
||||
+ "var",
|
||||
+ ],
|
||||
@@ ... @@
|
||||
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdatemyLib",
|
||||
@@ ... @@
|
||||
- "library": undefined,
|
||||
+ "library": Object {
|
||||
+ "auxiliaryComment": undefined,
|
||||
+ "export": undefined,
|
||||
+ "name": Array [
|
||||
+ "myLib",
|
||||
+ "[name]",
|
||||
+ ],
|
||||
+ "type": "var",
|
||||
+ "umdNamedDefine": undefined,
|
||||
+ },
|
||||
@@ ... @@
|
||||
- "uniqueName": "webpack",
|
||||
+ "uniqueName": "myLib",
|
||||
`)
|
||||
);
|
||||
test(
|
||||
"library.name contains [name] placeholder",
|
||||
{
|
||||
output: {
|
||||
library: {
|
||||
name: ["my[name]Lib", "[name]", "lib"],
|
||||
type: "var"
|
||||
}
|
||||
}
|
||||
},
|
||||
e =>
|
||||
e.toMatchInlineSnapshot(`
|
||||
- Expected
|
||||
+ Received
|
||||
|
||||
@@ ... @@
|
||||
- "chunkLoadingGlobal": "webpackChunkwebpack",
|
||||
+ "chunkLoadingGlobal": "webpackChunkmyLib_lib",
|
||||
@@ ... @@
|
||||
- "devtoolNamespace": "webpack",
|
||||
+ "devtoolNamespace": "myLib.lib",
|
||||
@@ ... @@
|
||||
- "enabledLibraryTypes": Array [],
|
||||
+ "enabledLibraryTypes": Array [
|
||||
+ "var",
|
||||
+ ],
|
||||
@@ ... @@
|
||||
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdatemyLib_lib",
|
||||
@@ ... @@
|
||||
- "library": undefined,
|
||||
+ "library": Object {
|
||||
+ "auxiliaryComment": undefined,
|
||||
+ "export": undefined,
|
||||
+ "name": Array [
|
||||
+ "my[name]Lib",
|
||||
+ "[name]",
|
||||
+ "lib",
|
||||
+ ],
|
||||
+ "type": "var",
|
||||
+ "umdNamedDefine": undefined,
|
||||
+ },
|
||||
@@ ... @@
|
||||
- "uniqueName": "webpack",
|
||||
+ "uniqueName": "myLib.lib",
|
||||
`)
|
||||
);
|
||||
test(
|
||||
"library.name.root contains [name] placeholder",
|
||||
{
|
||||
output: {
|
||||
library: {
|
||||
name: {
|
||||
root: ["[name]", "myLib"]
|
||||
},
|
||||
type: "var"
|
||||
}
|
||||
}
|
||||
},
|
||||
e =>
|
||||
e.toMatchInlineSnapshot(`
|
||||
- Expected
|
||||
+ Received
|
||||
|
||||
@@ ... @@
|
||||
- "chunkLoadingGlobal": "webpackChunkwebpack",
|
||||
+ "chunkLoadingGlobal": "webpackChunkmyLib",
|
||||
@@ ... @@
|
||||
- "devtoolNamespace": "webpack",
|
||||
+ "devtoolNamespace": "myLib",
|
||||
@@ ... @@
|
||||
- "enabledLibraryTypes": Array [],
|
||||
+ "enabledLibraryTypes": Array [
|
||||
+ "var",
|
||||
+ ],
|
||||
@@ ... @@
|
||||
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
|
||||
+ "hotUpdateGlobal": "webpackHotUpdatemyLib",
|
||||
@@ ... @@
|
||||
- "library": undefined,
|
||||
+ "library": Object {
|
||||
+ "auxiliaryComment": undefined,
|
||||
+ "export": undefined,
|
||||
+ "name": Object {
|
||||
+ "root": Array [
|
||||
+ "[name]",
|
||||
+ "myLib",
|
||||
+ ],
|
||||
+ },
|
||||
+ "type": "var",
|
||||
+ "umdNamedDefine": undefined,
|
||||
+ },
|
||||
@@ ... @@
|
||||
- "uniqueName": "webpack",
|
||||
+ "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