1
0
Fork 0
js-utils/config/rollup.js

132 lines
3.0 KiB
JavaScript
Raw Normal View History

import { join, sep } from 'path';
import commonjs from 'rollup-plugin-commonjs';
import { eslint } from 'rollup-plugin-eslint';
import json from 'rollup-plugin-json';
import multiEntry from 'rollup-plugin-multi-entry';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import visualizer from 'rollup-plugin-visualizer';
import yaml from 'rollup-plugin-yaml';
const flag_debug = process.env['DEBUG'] === 'TRUE';
const metadata = require('../package.json');
2019-09-29 21:06:03 +00:00
const external = require('./rollup-external.json').names;
const namedExports = require('./rollup-named.json');
const rootPath = process.env['ROOT_PATH'];
const targetPath = process.env['TARGET_PATH'];
const bundle = {
2019-09-29 21:06:03 +00:00
external,
input: {
include: [
join(rootPath, 'src', 'index.ts'),
join(rootPath, 'test', 'harness.ts'),
join(rootPath, 'test', '**', 'Test*.ts'),
],
},
manualChunks(id) {
if (id.includes(`${sep}test${sep}`)) {
2019-09-29 21:06:03 +00:00
return 'test';
}
if (id.match(/commonjs-external/i) || id.match(/commonjsHelpers/)) {
return 'vendor';
}
if (id.match(/node-resolve:/)) {
return 'vendor';
}
/* if (id.includes(`chai`) || id.includes(`sinon`)) {
return 'test';
} */
if (id.includes(`${sep}node_modules${sep}`)) {
return 'vendor';
}
if (id.includes(`${sep}src${sep}index`)) {
return 'index';
}
if (id.includes(`${sep}src${sep}`) || id.includes(`${sep}rules${sep}`)) {
return 'main';
}
2019-11-11 00:20:42 +00:00
if (flag_debug) {
console.log('file does not belong to any chunk:', id);
}
if (id.length === 30 && id.match(/^[a-f0-9]+$/)) {
return 'vendor';
2019-11-11 00:20:42 +00:00
}
return 'nochunk';
},
output: {
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
exports: 'named',
format: 'module',
minifyInternalExports: false,
sourcemap: true,
},
plugins: [
multiEntry(),
json(),
yaml(),
replace({
delimiters: ['{{ ', ' }}'],
values: {
BUILD_JOB: process.env['CI_JOB_ID'],
BUILD_RUNNER: process.env['CI_RUNNER_DESCRIPTION'],
GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'],
GIT_COMMIT: process.env['CI_COMMIT_SHA'],
NODE_VERSION: process.env['NODE_VERSION'],
2019-09-17 13:57:45 +00:00
PACKAGE_NAME: metadata.name,
PACKAGE_VERSION: metadata.version,
},
}),
resolve({
preferBuiltins: true,
}),
commonjs({
namedExports,
}),
globals(),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
2019-09-29 21:06:03 +00:00
join('node_modules', '**'),
join('src', 'resource'),
join('src', '**', '*.json'),
join('src', '**', '*.yml'),
],
include: [
join('src', '**', '*.ts'),
join('test', '**', '*.ts'),
],
throwOnError: true,
useEslintrc: false,
}),
typescript({
2019-09-29 21:06:03 +00:00
cacheRoot: join(targetPath, 'cache', 'rts2'),
rollupCommonJSResolveHack: true,
}),
visualizer({
filename: join(rootPath, 'out', 'bundle-graph.html'),
sourcemap: true,
}),
],
};
export default [
bundle,
];