build-module.js 1016 B

1234567891011121314151617181920212223242526272829303132333435
  1. const rollup = require( 'rollup' ).rollup;
  2. const resolve = require( '@rollup/plugin-node-resolve' ).nodeResolve;
  3. const esbuild = require( 'rollup-plugin-esbuild' ).default;
  4. const banner = require( './constants/banner' );
  5. const babel = require( '@rollup/plugin-babel' );
  6. const path = require( 'path' );
  7. const name = 'splide';
  8. function buildModule( type ) {
  9. return rollup( {
  10. input: './src/js/index.ts',
  11. plugins: [
  12. resolve(),
  13. esbuild(),
  14. babel.getBabelOutputPlugin( {
  15. configFile: path.resolve( __dirname, '../.babelrc' ),
  16. allowAllFormats: true,
  17. } ),
  18. ],
  19. } ).then( bundle => {
  20. return bundle.write( {
  21. banner,
  22. file : `./dist/js/${ name }.${ type }.js`,
  23. format : type,
  24. sourcemap: false,
  25. exports : 'named',
  26. } );
  27. } );
  28. }
  29. Promise.all( [ buildModule( 'cjs' ), buildModule( 'esm' ) ] ).catch( e => console.error( e ) );
  30. exports.buildCjs = () => buildModule( 'cjs' );
  31. exports.buildEsm = () => buildModule( 'esm' );