mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-05-17 03:09:39 +03:00
improve build and repo setup
This commit is contained in:
@@ -90,6 +90,7 @@ module.exports = {
|
||||
'./examples/**/tsconfig.json',
|
||||
'./website/**/tsconfig.json',
|
||||
'./local/**/tsconfig.json',
|
||||
'./tsconfig.json',
|
||||
],
|
||||
},
|
||||
env: {
|
||||
|
||||
@@ -37,13 +37,13 @@ module.exports = (resolve, options) => {
|
||||
const { rollup, paths, versions, alias, extractStyles, banner } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { dist: distPath } = paths;
|
||||
const { js: jsPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
return versions
|
||||
.map(({ format, generatedCode, file: filePathOverride, extension, minifiedVersion }) => {
|
||||
const needsGlobals = format === 'umd' || format === 'iife';
|
||||
const filePath = path.resolve(distPath, `${file}${extension || '.js'}`);
|
||||
const filePath = path.resolve(jsPath, `${file}${extension || '.js'}`);
|
||||
|
||||
const baseOutput = {
|
||||
...outputConfig,
|
||||
|
||||
@@ -12,7 +12,7 @@ module.exports = (resolve, options) => {
|
||||
const { rollup, paths, alias, extractStyles, banner } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { dist: distPath } = paths;
|
||||
const { js: jsPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
const output = {
|
||||
@@ -20,7 +20,7 @@ module.exports = (resolve, options) => {
|
||||
sourcemap,
|
||||
format: 'esm',
|
||||
generatedCode: 'es2015',
|
||||
file: path.resolve(distPath, `${file}.js`),
|
||||
file: path.resolve(jsPath, `${file}.js`),
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const fs = require('fs');
|
||||
const { basename } = require('path');
|
||||
const path = require('path');
|
||||
const rollupDts = require('rollup-plugin-dts');
|
||||
|
||||
@@ -27,7 +26,7 @@ module.exports = (resolve, options) => {
|
||||
plugins: [rollupTs(input, true)],
|
||||
},
|
||||
{
|
||||
input: path.join(typesPath, `${basename(input).replace('.ts', '.d.ts')}`),
|
||||
input: path.join(typesPath, `${path.basename(input).replace('.ts', '.d.ts')}`),
|
||||
output: {
|
||||
file: dtsOutput,
|
||||
},
|
||||
@@ -48,7 +47,7 @@ module.exports = (resolve, options) => {
|
||||
writeBundle() {
|
||||
const filesAndDirs = fs.readdirSync(typesPath);
|
||||
filesAndDirs.forEach((fileOrDir) => {
|
||||
if (basename(fileOrDir) !== basename(dtsOutput)) {
|
||||
if (path.basename(fileOrDir) !== path.basename(dtsOutput)) {
|
||||
fs.rmSync(path.join(typesPath, fileOrDir), { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -30,6 +30,7 @@ const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||
|
||||
const mergeAndResolveOptions = (userOptions) => {
|
||||
const {
|
||||
outDir: defaultOutDir,
|
||||
paths: defaultPaths,
|
||||
versions: defaultVersions,
|
||||
alias: defaultAlias,
|
||||
@@ -42,6 +43,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
} = defaultOptions;
|
||||
const {
|
||||
project,
|
||||
outDir: rawOutDir,
|
||||
paths: rawPaths = {},
|
||||
alias: rawAlias = {},
|
||||
rollup: rawRollup = {},
|
||||
@@ -64,6 +66,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
banner: rawBanner ?? defaultBanner,
|
||||
versions: rawVersions ?? defaultVersions,
|
||||
useEsbuild: rawUseEsbuild ?? defaultUseEsbuild,
|
||||
outDir: rawOutDir ?? defaultOutDir,
|
||||
paths: {
|
||||
...defaultPaths,
|
||||
...rawPaths,
|
||||
@@ -83,13 +86,14 @@ const mergeAndResolveOptions = (userOptions) => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const { dist, types, styles } = mergedOptions.paths;
|
||||
const { outDir, paths } = mergedOptions;
|
||||
const { js, types, styles } = paths;
|
||||
const pluginFromFn = (plugin) =>
|
||||
typeof plugin === 'function' ? plugin(mergedOptions, workspaceRoot, workspaces) : plugin;
|
||||
|
||||
mergedOptions.paths.dist = resolvePath(projectPath, dist);
|
||||
mergedOptions.paths.types = resolvePath(projectPath, types);
|
||||
mergedOptions.paths.styles = resolvePath(projectPath, styles);
|
||||
paths.js = resolvePath(projectPath, path.join(outDir, js));
|
||||
paths.types = resolvePath(projectPath, path.join(outDir, types));
|
||||
paths.styles = resolvePath(projectPath, path.join(outDir, styles));
|
||||
|
||||
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
|
||||
mergedOptions.rollup.output = {
|
||||
|
||||
@@ -3,8 +3,9 @@ module.exports = {
|
||||
verbose: false,
|
||||
banner: null,
|
||||
useEsbuild: false,
|
||||
outDir: './dist',
|
||||
paths: {
|
||||
dist: './dist',
|
||||
js: '.',
|
||||
types: './types',
|
||||
styles: './styles',
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ const portRange = {
|
||||
};
|
||||
|
||||
const paths = {
|
||||
dist: './.build',
|
||||
outDir: './.build',
|
||||
input: './index.browser',
|
||||
html: './index.html',
|
||||
};
|
||||
@@ -30,7 +30,7 @@ module.exports = (testDir, useEsbuild, dev) => {
|
||||
}, {});
|
||||
|
||||
const { min, max } = portRange;
|
||||
const { dist, input, html: htmlPath } = testPaths;
|
||||
const { outDir, input, html: htmlPath } = testPaths;
|
||||
const name = path.basename(testDir);
|
||||
const htmlName = `${name}.html`;
|
||||
const port = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
@@ -43,9 +43,7 @@ module.exports = (testDir, useEsbuild, dev) => {
|
||||
banner: testDir,
|
||||
extractStyle: false,
|
||||
extractTypes: false,
|
||||
paths: {
|
||||
dist,
|
||||
},
|
||||
outDir,
|
||||
versions: [
|
||||
{
|
||||
format: 'iife',
|
||||
@@ -53,30 +51,6 @@ module.exports = (testDir, useEsbuild, dev) => {
|
||||
minifiedVersion: false,
|
||||
},
|
||||
],
|
||||
// if the import would be 'overlayscrollbars' and the package name is also 'overlayscrollbars' esbuild needs an alias to resolve it correctly
|
||||
alias: (workspaceRoot, workspaces, resolvePath) =>
|
||||
workspaces.reduce((obj, resolvedPath) => {
|
||||
const absolutePath = path.resolve(workspaceRoot, resolvedPath);
|
||||
try {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const projTsConfig = require(`${path.resolve(
|
||||
workspaceRoot,
|
||||
resolvedPath
|
||||
)}/tsconfig.json`);
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const projPackageJson = require(`${path.resolve(
|
||||
workspaceRoot,
|
||||
resolvedPath
|
||||
)}/package.json`);
|
||||
|
||||
const { name: projectName } = projPackageJson;
|
||||
const { compilerOptions } = projTsConfig;
|
||||
const { baseUrl } = compilerOptions;
|
||||
|
||||
obj[projectName] = resolvePath(absolutePath, path.join(baseUrl, projectName), true);
|
||||
} catch {}
|
||||
return obj;
|
||||
}, {}),
|
||||
rollup: {
|
||||
input,
|
||||
context: 'this',
|
||||
@@ -91,7 +65,7 @@ module.exports = (testDir, useEsbuild, dev) => {
|
||||
),
|
||||
rollupPluginServe({
|
||||
port,
|
||||
contentBase: dist,
|
||||
contentBase: outDir,
|
||||
historyApiFallback: `/${htmlName}`,
|
||||
host: '127.0.0.1',
|
||||
verbose: isDev,
|
||||
@@ -102,7 +76,7 @@ module.exports = (testDir, useEsbuild, dev) => {
|
||||
isDev && rollupAdditionalWatchFiles([htmlPath]),
|
||||
isDev &&
|
||||
rollupPluginLivereload({
|
||||
watch: dist,
|
||||
watch: outDir,
|
||||
port: port - 1,
|
||||
verbose: false,
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "@~local/tsconfig"
|
||||
}
|
||||
Reference in New Issue
Block a user