Skip to content

Drop folder #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,6 @@ function escapeLocalIdent(localident) {
);
}

function resolveFolderTemplate(loaderContext, localIdentName, options) {
const { context } = options;
let { resourcePath } = loaderContext;
const parsed = path.parse(loaderContext.resourcePath);

if (parsed.dir) {
resourcePath = parsed.dir + path.sep;
}

let directory = path
.relative(context, `${resourcePath}_`)
.replace(/\\/g, "/")
.replace(/\.\.(\/)?/g, "_$1");
directory = directory.substr(0, directory.length - 1);

let folder = "";

if (directory.length > 1) {
folder = path.basename(directory);
}

return localIdentName.replace(/\[folder\]/gi, () => folder);
}

function defaultGetLocalIdent(
loaderContext,
localIdentName,
Expand Down Expand Up @@ -396,10 +372,10 @@ function defaultGetLocalIdent(
.replace(/[/+]/g, "_")
.replace(/^\d/g, "_");

// TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property
const ext = path.extname(loaderContext.resourcePath);
const base = path.basename(loaderContext.resourcePath);
const name = base.slice(0, base.length - ext.length);

const data = {
filename: path.relative(options.context, loaderContext.resourcePath),
contentHash: localIdentHash,
Expand All @@ -411,20 +387,7 @@ function defaultGetLocalIdent(
};

// eslint-disable-next-line no-underscore-dangle
let interpolatedFilename = loaderContext._compilation.getPath(
localIdentName,
data
);

if (localIdentName.includes("[folder]")) {
interpolatedFilename = resolveFolderTemplate(
loaderContext,
interpolatedFilename,
options
);
}

return interpolatedFilename;
return loaderContext._compilation.getPath(localIdentName, data);
}

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

if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
loaderContext.emitWarning(
"Emoji is deprecated and will be removed in next major release."
);
}

if (modulesOptions.localIdentName.includes("[folder]")) {
loaderContext.emitWarning(
"[folder] is deprecated and will be removed in next major release. See documentation for available options (https://github.com/webpack-contrib/css-loader#localidentname)"
);
}

return modulesOptions;
}

Expand Down
Loading