Skip to content

Commit

Permalink
feat(build): Add custom rollup config for core
Browse files Browse the repository at this point in the history
The `core` package has some unique characteristics that need a custom rollup config file rather
than using the generic one from `@spinnaker/scripts`. This includes

- copying over typescript definition files
- defining an alias mapping for `root`
- a plugin to fix typescript's path auto-rewrites.
  • Loading branch information
vigneshm committed Jun 4, 2021
1 parent c0f30c9 commit f0ac239
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/scripts/modules/core/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import alias from '@rollup/plugin-alias';
import fs from 'fs';
import path from 'path';
import copy from 'rollup-plugin-copy';

import baseRollupConfig from '@spinnaker/scripts/config/rollup.config.base.module';
import externalConfigurer from '@spinnaker/scripts/helpers/rollup-node-auto-external-configurer';

const packageJSON = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const externals = {
...packageJSON.dependencies,
'root/version': true,
};

const fixTSPathRewrite = () => {
return {
name: 'fixTSPathRewrite',
writeBundle: () => {
const dts = path.join(__dirname, 'dist', 'index.d.ts');
const fixed = fs
.readFileSync(dts)
.toString()
.replace(/types="core\/types"/, 'types="./types"');
fs.writeFileSync(dts, fixed);
},
};
};

export default {
...baseRollupConfig,
plugins: [
...baseRollupConfig.plugins,
alias({
entries: [{ find: 'root', replacement: path.join(__dirname, '../../../../') }],
}),
copy({
targets: [{ src: 'src/types/**/*', dest: 'dist/types' }],
}),
fixTSPathRewrite(),
],
external: externalConfigurer(externals),
};

0 comments on commit f0ac239

Please sign in to comment.