mirror of
https://github.com/directus/directus.git
synced 2026-02-01 15:05:04 -05:00
This includes using the official rollup plugins where possible, using dedicated builds for node and browsers and minifying production builds.
101 lines
1.9 KiB
JavaScript
101 lines
1.9 KiB
JavaScript
import json from '@rollup/plugin-json';
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import typescript from 'rollup-plugin-typescript2';
|
|
import sourceMaps from 'rollup-plugin-sourcemaps';
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
import pkg from './package.json';
|
|
|
|
const globalName = 'formatTitle';
|
|
|
|
const configs = {
|
|
global: {
|
|
file: pkg.unpkg,
|
|
format: 'iife',
|
|
target: 'es5',
|
|
mode: 'production',
|
|
browser: true,
|
|
},
|
|
browser: {
|
|
file: pkg.module.replace('bundler', 'esm'),
|
|
format: 'es',
|
|
target: 'es2018',
|
|
mode: 'production',
|
|
browser: true,
|
|
},
|
|
bundler: {
|
|
file: pkg.module,
|
|
format: 'es',
|
|
target: 'esnext',
|
|
mode: 'development',
|
|
},
|
|
cjs: {
|
|
file: pkg.main,
|
|
format: 'cjs',
|
|
target: 'esnext',
|
|
mode: 'development',
|
|
},
|
|
};
|
|
|
|
function createConfig({
|
|
file,
|
|
format,
|
|
target,
|
|
mode,
|
|
browser = false,
|
|
external = Object.fromEntries(Object.keys(pkg.dependencies || {}).map((x) => [x, x])),
|
|
}) {
|
|
const isProduction = mode === 'production';
|
|
|
|
const config = {
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: isProduction && !file.endsWith('.min.js') ? file.replace('.js', '.min.js') : file,
|
|
format,
|
|
exports: 'auto',
|
|
sourcemap: true,
|
|
},
|
|
external: Object.keys(external),
|
|
watch: {
|
|
include: 'src/**/*',
|
|
},
|
|
plugins: [
|
|
json(),
|
|
typescript({
|
|
useTsconfigDeclarationDir: true,
|
|
tsconfigOverride: {
|
|
compilerOptions: {
|
|
target,
|
|
lib: [target],
|
|
},
|
|
},
|
|
}),
|
|
resolve({ browser }),
|
|
commonjs(),
|
|
sourceMaps(),
|
|
],
|
|
};
|
|
|
|
if (format === 'iife') {
|
|
config.output.name = globalName;
|
|
config.output.globals = external;
|
|
}
|
|
|
|
if (isProduction) {
|
|
config.plugins.push(
|
|
terser({
|
|
ecma: target.replace('es', ''),
|
|
})
|
|
);
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
function createConfigs(configs) {
|
|
return Object.keys(configs).map((key) => createConfig(configs[key]));
|
|
}
|
|
|
|
export default createConfigs(configs);
|