-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Before version 4 it was possible to analyze the contents of the file being processed (and its path) and generate inserted content dynamically based on the current file data.
Starting from version 4, it seems to be impossible to analyze file data during modification.
Here is an example of how we used version 3 of the plugin:
new ModifySourcePlugin({
rules: [
{
test: /antd\/[^/]+(\/[^/]+)?\/style\/[^/]+\.less/,
modify: (src, filePath) => {
const directoryPath = path.dirname(filePath);
const variablesRelativePath = path.relative(
directoryPath,
'src/styles/common/variables.less',
);
const filePathMatch = filePath.match(
/antd\/[^/]+\/([^/]+)\/style\/[^/]+\.less$/,
);
let overridesImport;
if (!filePathMatch) {
overridesImport = '';
} else {
const [, componentName] = filePathMatch;
const overridesPath = `src/styles/ant/${componentName}.less`;
const overridesRelativePath = path.relative(
directoryPath,
overridesPath,
);
overridesImport = existsSync(overridesPath)
? `@import '${overridesRelativePath}';${EOL}`
: '';
}
return `${src}${EOL}@import '${variablesRelativePath}';${EOL}${overridesImport}`;
},
},
],
})
I thought that we needed to write a custom operation for it, but it seems like there is no way to get current file info inside the operation.
Is it possible to get the same behaviour with version 4?
artembatura and rossanmol
Metadata
Metadata
Assignees
Labels
No labels