fix(config): update .smartconfig.json handling and harden bundler runtime compatibility
This commit is contained in:
+13
-15
@@ -21,30 +21,28 @@ export class HtmlHandler {
|
||||
to?: string;
|
||||
minify?: boolean;
|
||||
}) {
|
||||
optionsArg = {
|
||||
...{
|
||||
from: this.defaultFromPath,
|
||||
to: this.defaultToPath,
|
||||
minify: false,
|
||||
},
|
||||
const options = {
|
||||
from: this.defaultFromPath,
|
||||
to: this.defaultToPath,
|
||||
minify: false,
|
||||
...optionsArg,
|
||||
};
|
||||
if (await this.checkIfExists()) {
|
||||
console.log(`${optionsArg.from} replaces file at ${optionsArg.to}`);
|
||||
console.log(`${options.from} replaces file at ${options.to}`);
|
||||
}
|
||||
optionsArg.from = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.from,
|
||||
options.from = plugins.smartpath.transform.toAbsolute(
|
||||
options.from,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
optionsArg.to = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.to,
|
||||
options.to = plugins.smartpath.transform.toAbsolute(
|
||||
options.to,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
let fileString = (await plugins.fs
|
||||
.file(optionsArg.from)
|
||||
.file(options.from)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
if (optionsArg.minify) {
|
||||
if (options.minify) {
|
||||
fileString = plugins.htmlMinifier.minify(fileString, {
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
@@ -56,9 +54,9 @@ export class HtmlHandler {
|
||||
removeComments: true,
|
||||
});
|
||||
}
|
||||
const toDir = plugins.path.dirname(optionsArg.to);
|
||||
const toDir = plugins.path.dirname(options.to);
|
||||
await plugins.fs.directory(toDir).create();
|
||||
await plugins.fs.file(optionsArg.to).encoding('utf8').write(fileString);
|
||||
await plugins.fs.file(options.to).encoding('utf8').write(fileString);
|
||||
console.log(`html processing succeeded!`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user