feat(core): Integrate Rolldown as optional bundler, migrate filesystem to smartfs, and update bundler/tooling
This commit is contained in:
@@ -2,11 +2,17 @@ import * as plugins from './plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
|
||||
export class HtmlHandler {
|
||||
public defaultFromPath: string = plugins.path.join(paths.htmlDir, 'index.html');
|
||||
public defaultToPath: string = plugins.path.join(paths.distServeDir, 'index.html');
|
||||
public defaultFromPath: string = plugins.path.join(
|
||||
paths.htmlDir,
|
||||
'index.html',
|
||||
);
|
||||
public defaultToPath: string = plugins.path.join(
|
||||
paths.distServeDir,
|
||||
'index.html',
|
||||
);
|
||||
|
||||
public async checkIfExists() {
|
||||
return plugins.smartfile.fs.fileExists(this.defaultFromPath);
|
||||
return await plugins.fs.file(this.defaultFromPath).exists();
|
||||
}
|
||||
|
||||
// copies the html
|
||||
@@ -16,19 +22,28 @@ export class HtmlHandler {
|
||||
minify?: boolean;
|
||||
}) {
|
||||
optionsArg = {
|
||||
... {
|
||||
...{
|
||||
from: this.defaultFromPath,
|
||||
to: this.defaultToPath,
|
||||
minify: false,
|
||||
},
|
||||
...optionsArg
|
||||
}
|
||||
...optionsArg,
|
||||
};
|
||||
if (await this.checkIfExists()) {
|
||||
console.log(`${optionsArg.from} replaces file at ${optionsArg.to}`);
|
||||
}
|
||||
optionsArg.from = plugins.smartpath.transform.toAbsolute(optionsArg.from, paths.cwd) as string;
|
||||
optionsArg.to = plugins.smartpath.transform.toAbsolute(optionsArg.to, paths.cwd) as string;
|
||||
let fileString = plugins.smartfile.fs.toStringSync(optionsArg.from);
|
||||
optionsArg.from = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.from,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
optionsArg.to = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.to,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
let fileString = (await plugins.fs
|
||||
.file(optionsArg.from)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
if (optionsArg.minify) {
|
||||
fileString = plugins.htmlMinifier.minify(fileString, {
|
||||
minifyCSS: true,
|
||||
@@ -41,7 +56,9 @@ export class HtmlHandler {
|
||||
removeComments: true,
|
||||
});
|
||||
}
|
||||
await plugins.smartfile.memory.toFs(fileString, optionsArg.to);
|
||||
const toDir = plugins.path.dirname(optionsArg.to);
|
||||
await plugins.fs.directory(toDir).create();
|
||||
await plugins.fs.file(optionsArg.to).encoding('utf8').write(fileString);
|
||||
console.log(`html processing succeeded!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,4 @@ export * from '../plugins.js';
|
||||
|
||||
import * as htmlMinifier from 'html-minifier';
|
||||
|
||||
export {
|
||||
htmlMinifier
|
||||
}
|
||||
export { htmlMinifier };
|
||||
|
||||
Reference in New Issue
Block a user