Skip to content

Commit b1548e5

Browse files
refactor: drop [folder] and [emoji]
1 parent faca47b commit b1548e5

File tree

3 files changed

+3
-481
lines changed

3 files changed

+3
-481
lines changed

src/utils.js

+2-51
Original file line numberDiff line numberDiff line change
@@ -311,30 +311,6 @@ function escapeLocalIdent(localident) {
311311
);
312312
}
313313

314-
function resolveFolderTemplate(loaderContext, localIdentName, options) {
315-
const { context } = options;
316-
let { resourcePath } = loaderContext;
317-
const parsed = path.parse(loaderContext.resourcePath);
318-
319-
if (parsed.dir) {
320-
resourcePath = parsed.dir + path.sep;
321-
}
322-
323-
let directory = path
324-
.relative(context, `${resourcePath}_`)
325-
.replace(/\\/g, "/")
326-
.replace(/\.\.(\/)?/g, "_$1");
327-
directory = directory.substr(0, directory.length - 1);
328-
329-
let folder = "";
330-
331-
if (directory.length > 1) {
332-
folder = path.basename(directory);
333-
}
334-
335-
return localIdentName.replace(/\[folder\]/gi, () => folder);
336-
}
337-
338314
function defaultGetLocalIdent(
339315
loaderContext,
340316
localIdentName,
@@ -396,10 +372,10 @@ function defaultGetLocalIdent(
396372
.replace(/[/+]/g, "_")
397373
.replace(/^\d/g, "_");
398374

375+
// TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property
399376
const ext = path.extname(loaderContext.resourcePath);
400377
const base = path.basename(loaderContext.resourcePath);
401378
const name = base.slice(0, base.length - ext.length);
402-
403379
const data = {
404380
filename: path.relative(options.context, loaderContext.resourcePath),
405381
contentHash: localIdentHash,
@@ -411,20 +387,7 @@ function defaultGetLocalIdent(
411387
};
412388

413389
// eslint-disable-next-line no-underscore-dangle
414-
let interpolatedFilename = loaderContext._compilation.getPath(
415-
localIdentName,
416-
data
417-
);
418-
419-
if (localIdentName.includes("[folder]")) {
420-
interpolatedFilename = resolveFolderTemplate(
421-
loaderContext,
422-
interpolatedFilename,
423-
options
424-
);
425-
}
426-
427-
return interpolatedFilename;
390+
return loaderContext._compilation.getPath(localIdentName, data);
428391
}
429392

430393
const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
@@ -609,18 +572,6 @@ function getModulesOptions(rawOptions, loaderContext) {
609572
}
610573
}
611574

612-
if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
613-
loaderContext.emitWarning(
614-
"Emoji is deprecated and will be removed in next major release."
615-
);
616-
}
617-
618-
if (modulesOptions.localIdentName.includes("[folder]")) {
619-
loaderContext.emitWarning(
620-
"[folder] is deprecated and will be removed in next major release. See documentation for available options (https://github.com/webpack-contrib/css-loader#localidentname)"
621-
);
622-
}
623-
624575
return modulesOptions;
625576
}
626577

0 commit comments

Comments
 (0)