mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 20:00:36 +03:00
improve build setup
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
const path = require('path');
|
||||
const { rollupVirtual } = require('./plugins');
|
||||
|
||||
module.exports = (_, options) => {
|
||||
const { extractPackageJson, outDir } = options;
|
||||
|
||||
const {
|
||||
input = './package.json',
|
||||
output = './package.json',
|
||||
json,
|
||||
} = typeof extractPackageJson === 'object' ? extractPackageJson : {};
|
||||
const resolvedInput = path.resolve(input);
|
||||
const inputPackageJson = require(resolvedInput);
|
||||
|
||||
return {
|
||||
input: resolvedInput,
|
||||
onwarn: (warning, warn) => {
|
||||
if (warning.code !== 'EMPTY_BUNDLE') {
|
||||
warn(warning);
|
||||
}
|
||||
},
|
||||
output: {
|
||||
file: path.resolve(outDir, output),
|
||||
},
|
||||
plugins: [
|
||||
rollupVirtual({
|
||||
[resolvedInput]: '',
|
||||
}),
|
||||
{
|
||||
generateBundle(__, bundle) {
|
||||
const bundleKeys = Object.keys(bundle);
|
||||
if (bundleKeys.length > 1) {
|
||||
throw new Error('Unexpected entries length.');
|
||||
}
|
||||
bundle[bundleKeys[0]].code = JSON.stringify(
|
||||
typeof json === 'function' ? json(inputPackageJson) : inputPackageJson,
|
||||
null,
|
||||
2
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
const { rollupVirtual } = require('./plugins');
|
||||
const rollupPluginClean = require('../plugins/clean');
|
||||
const rollupPluginCopy = require('../plugins/copy');
|
||||
const rollupPluginPackageJson = require('../plugins/packageJson');
|
||||
|
||||
module.exports = (_, options) => {
|
||||
const { project, verbose, clean, copy, outDir, projectDir, extractPackageJson } = options;
|
||||
|
||||
return {
|
||||
input: 'preBuild',
|
||||
onwarn: (warning, warn) => {
|
||||
if (warning.code !== 'EMPTY_BUNDLE') {
|
||||
warn(warning);
|
||||
}
|
||||
},
|
||||
output: {
|
||||
dir: outDir,
|
||||
},
|
||||
plugins: [
|
||||
verbose && {
|
||||
name: 'PROJECT',
|
||||
buildStart() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('PROJECT : ', project);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('OPTIONS : ', options);
|
||||
},
|
||||
},
|
||||
clean && outDir !== projectDir && rollupPluginClean({ paths: [outDir], verbose }),
|
||||
extractPackageJson && rollupPluginPackageJson(extractPackageJson),
|
||||
copy && rollupPluginCopy({ paths: copy, verbose }),
|
||||
rollupVirtual({
|
||||
preBuild: '',
|
||||
}),
|
||||
{
|
||||
generateBundle(__, bundle) {
|
||||
const virtualEntry = Object.keys(bundle).find((key) => key.includes('virtual'));
|
||||
if (virtualEntry) {
|
||||
delete bundle[virtualEntry];
|
||||
}
|
||||
},
|
||||
},
|
||||
].filter(Boolean),
|
||||
};
|
||||
};
|
||||
@@ -7,7 +7,6 @@ const glob = require('glob');
|
||||
const resolve = require('@~local/config/resolve');
|
||||
const defaultOptions = require('./defaultOptions');
|
||||
const pipelineDefault = require('./pipeline.default');
|
||||
const rollupPluginClean = require('./plugins/clean');
|
||||
|
||||
const workspaceRoot = path.dirname(execSync('npm root').toString());
|
||||
const pkg = require(`${workspaceRoot}/package.json`);
|
||||
@@ -32,6 +31,7 @@ const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||
const mergeAndResolveOptions = (userOptions) => {
|
||||
const {
|
||||
clean: defaultClean,
|
||||
copy: defaultCopy,
|
||||
outDir: defaultOutDir,
|
||||
paths: defaultPaths,
|
||||
versions: defaultVersions,
|
||||
@@ -47,6 +47,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
const {
|
||||
project,
|
||||
clean: rawClean,
|
||||
copy: rawCopy,
|
||||
outDir: rawOutDir,
|
||||
paths: rawPaths = {},
|
||||
alias: rawAlias = {},
|
||||
@@ -74,6 +75,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
versions: rawVersions ?? defaultVersions,
|
||||
useEsbuild: rawUseEsbuild ?? defaultUseEsbuild,
|
||||
clean: rawClean ?? defaultClean,
|
||||
copy: rawCopy ?? defaultCopy,
|
||||
outDir: rawOutDir ?? defaultOutDir,
|
||||
paths: {
|
||||
...defaultPaths,
|
||||
@@ -120,26 +122,9 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
|
||||
const createConfig = (userOptions = {}) => {
|
||||
const options = mergeAndResolveOptions(userOptions);
|
||||
const { project, useEsbuild, verbose, clean, outDir, projectDir } = options;
|
||||
const { useEsbuild } = options;
|
||||
const result = pipelineDefault(resolve, options, useEsbuild);
|
||||
const resultArr = Array.isArray(result) ? result : [result];
|
||||
const prePlugins = !Array.isArray(resultArr[0].plugins) ? [] : resultArr[0].plugins;
|
||||
|
||||
resultArr[0].plugins = prePlugins;
|
||||
|
||||
if (verbose) {
|
||||
prePlugins.push({
|
||||
name: 'PROJECT',
|
||||
buildStart() {
|
||||
console.log('');
|
||||
console.log('PROJECT : ', project);
|
||||
console.log('OPTIONS : ', options);
|
||||
},
|
||||
});
|
||||
}
|
||||
if (clean && outDir !== projectDir) {
|
||||
prePlugins.push(rollupPluginClean({ paths: [outDir], verbose }));
|
||||
}
|
||||
|
||||
return resultArr;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ module.exports = {
|
||||
useEsbuild: false,
|
||||
outDir: './dist',
|
||||
clean: false,
|
||||
copy: false,
|
||||
paths: {
|
||||
js: '.',
|
||||
types: './types',
|
||||
|
||||
@@ -2,16 +2,16 @@ const bundleScriptDefault = require('./bundle/script.default');
|
||||
const bundleScriptEsbuild = require('./bundle/script.esbuild');
|
||||
const bundleStyles = require('./bundle/styles');
|
||||
const bundleTypes = require('./bundle/types');
|
||||
const bundlePackageJson = require('./bundle/packageJson');
|
||||
const preBuild = require('./bundle/pre');
|
||||
|
||||
module.exports = (resolve, options, esbuild) => {
|
||||
const { extractTypes, extractStyles, extractPackageJson } = options;
|
||||
const { extractTypes, extractStyles } = options;
|
||||
const bundleScript = esbuild ? bundleScriptEsbuild : bundleScriptDefault;
|
||||
|
||||
const pkgJson = extractPackageJson && bundlePackageJson(resolve, options);
|
||||
const pre = preBuild(resolve, options);
|
||||
const styles = extractStyles && bundleStyles(resolve, options);
|
||||
const types = extractTypes && bundleTypes(resolve, options);
|
||||
const js = bundleScript(resolve, options);
|
||||
|
||||
return [pkgJson, styles, types, js].flat().filter((build) => !!build);
|
||||
return [pre, styles, types, js].flat().filter((build) => !!build);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user