improve build setup

This commit is contained in:
Rene Haas
2022-10-31 14:27:42 +01:00
parent 3d095f747d
commit 5e0e21c89e
12 changed files with 144 additions and 75 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ module.exports = ({ paths = [], verbose = false } = {}) => {
let cleaned = false;
return {
name: 'clean',
async buildStart() {
buildStart() {
if (!cleaned) {
paths.forEach((currPath) => {
const resolvedPath = path.resolve(currPath);
+25
View File
@@ -0,0 +1,25 @@
const path = require('path');
const fs = require('fs');
module.exports = ({ paths = [], verbose = false } = {}) => {
return {
name: 'copy',
buildStart() {
paths.forEach((currPath) => {
const resolvedPath = path.resolve(currPath);
if (fs.existsSync(resolvedPath)) {
if (verbose) {
// eslint-disable-next-line no-console
console.log(`Copy: ${resolvedPath}`);
}
this.emitFile({
type: 'asset',
source: fs.readFileSync(resolvedPath),
fileName: path.basename(resolvedPath),
});
}
});
},
};
};
+20
View File
@@ -0,0 +1,20 @@
const path = require('path');
module.exports = ({ input = 'package.json', output = 'package.json', json } = {}) => {
const resolvedInput = path.resolve(input);
const inputPackageJson = require(resolvedInput);
return {
name: 'packageJson',
buildStart() {
this.emitFile({
type: 'asset',
source: JSON.stringify(
typeof json === 'function' ? json(inputPackageJson) : inputPackageJson,
null,
2
),
fileName: output,
});
},
};
};