Allow minifiers to get source path of file

This commit is contained in:
zodern
2022-02-28 14:00:28 -06:00
parent ed20430144
commit 93eedb5cea
4 changed files with 17 additions and 3 deletions

View File

@@ -127,8 +127,7 @@ const mergeCss = Profile("mergeCss", async function (css, postcssConfig) {
const result = await postcssConfig.postcss(
postcssConfig.plugins
).process(content, {
// TODO: provide a better way to get the file's path
from: process.cwd() + file._source.url?.replace('/__cordova', ''),
from: file.getSourcePath(),
parser: postcssConfig.options.parser
});

View File

@@ -1126,11 +1126,17 @@ class Target {
return null;
}
let sourcePath;
if (resource.data && resource.sourceRoot && resource.sourcePath) {
sourcePath = files.pathJoin(resource.sourceRoot, resource.sourcePath);
}
const file = new File({
info: 'resource ' + resource.servePath,
arch: target.arch,
data: resource.data,
hash: resource.hash,
sourcePath
});
file.setTargetPathFromRelPath(
@@ -1279,13 +1285,18 @@ class Target {
return;
}
let sourcePath;
if (resource.data && resource.sourceRoot && resource.sourcePath) {
sourcePath = files.pathJoin(resource.sourceRoot, resource.sourcePath);
}
const f = new File({
info: 'resource ' + resource.servePath,
arch: this.arch,
data: resource.data,
hash: resource.hash,
cacheable: false,
replaceable: resource.type === 'js' && sourceBatch.hmrAvailable
replaceable: resource.type === 'js' && sourceBatch.hmrAvailable,
sourcePath
});
const relPath = stripLeadingSlash(resource.servePath);

View File

@@ -892,6 +892,7 @@ class OutputResource {
sourcePath,
targetPath,
servePath,
sourceRoot: resourceSlot.packageSourceBatch.sourceRoot,
// Remember the source hash so that changes to the source that
// disappear after compilation can still contribute to the hash.
// Bypassing SourceResource.hash getter so if the compiler plugin doesn't

View File

@@ -36,6 +36,9 @@ class InputFile extends buildPluginModule.InputFile {
getArch() {
return this._arch;
}
getSourcePath() {
return this._source.sourcePath || null;
}
error({message, sourcePath, line, column, func}) {
const relPath = this.getPathInBundle();