1- 'use strict' ;
2-
3- const commonjs = require ( '@rollup/plugin-commonjs' ) ;
4- const { nodeResolve } = require ( '@rollup/plugin-node-resolve' ) ;
5- const { terser } = require ( 'rollup-plugin-terser' ) ;
6- const typescript = require ( 'rollup-plugin-typescript2' ) ;
7- const handlebars = require ( 'handlebars' ) ;
8- const path = require ( 'path' ) ;
9- const fs = require ( 'fs' ) ;
10-
11- const pkg = require ( './package.json' ) ;
12- const external = Object . keys ( pkg . dependencies ) ;
1+ import alias from '@rollup/plugin-alias' ;
2+ import commonjs from '@rollup/plugin-commonjs' ;
3+ import { nodeResolve } from '@rollup/plugin-node-resolve' ;
4+ import typescript from '@rollup/plugin-typescript' ;
5+ import { readFileSync } from 'fs' ;
6+ import { precompile } from 'handlebars' ;
7+ import { dirname , extname , resolve } from 'path' ;
8+ import externals from 'rollup-plugin-node-externals' ;
9+ import { terser } from 'rollup-plugin-terser' ;
1310
1411/**
1512 * Custom plugin to parse handlebar imports and precompile
@@ -18,15 +15,15 @@ const external = Object.keys(pkg.dependencies);
1815 */
1916const handlebarsPlugin = ( ) => ( {
2017 resolveId : ( file , importer ) => {
21- if ( path . extname ( file ) === '.hbs' ) {
22- return path . resolve ( path . dirname ( importer ) , file ) ;
18+ if ( extname ( file ) === '.hbs' ) {
19+ return resolve ( dirname ( importer ) , file ) ;
2320 }
2421 return null ;
2522 } ,
26- load : ( file ) => {
27- if ( path . extname ( file ) === '.hbs' ) {
28- const template = fs . readFileSync ( file , 'utf8' ) . toString ( ) . trim ( ) ;
29- const templateSpec = handlebars . precompile ( template , {
23+ load : file => {
24+ if ( extname ( file ) === '.hbs' ) {
25+ const template = readFileSync ( file , 'utf8' ) . toString ( ) . trim ( ) ;
26+ const templateSpec = precompile ( template , {
3027 strict : true ,
3128 noEscape : true ,
3229 preventIndent : true ,
@@ -38,43 +35,45 @@ const handlebarsPlugin = () => ({
3835 union : true ,
3936 intersection : true ,
4037 enumerator : true ,
41- escapeQuotes : true ,
4238 } ,
4339 } ) ;
4440 return `export default ${ templateSpec } ;` ;
4541 }
4642 return null ;
47- }
43+ } ,
4844} ) ;
4945
5046const getPlugins = ( ) => {
5147 const plugins = [
52- handlebarsPlugin ( ) ,
53- typescript ( ) ,
48+ externals ( {
49+ deps : true ,
50+ } ) ,
5451 nodeResolve ( ) ,
55- commonjs ( ) ,
56- ]
52+ commonjs ( {
53+ sourceMap : false ,
54+ } ) ,
55+ handlebarsPlugin ( ) ,
56+ typescript ( {
57+ module : 'esnext' ,
58+ } ) ,
59+ alias ( {
60+ entries : {
61+ handlebars : 'handlebars/lib/handlebars.runtime' ,
62+ } ,
63+ } ) ,
64+ ] ;
5765 if ( process . env . NODE_ENV === 'development' ) {
5866 return plugins ;
5967 }
6068 return [ ...plugins , terser ( ) ] ;
6169} ;
6270
63- module . exports = {
71+ export default {
6472 input : './src/index.ts' ,
6573 output : {
74+ exports : 'named' ,
6675 file : './dist/index.js' ,
6776 format : 'cjs' ,
6877 } ,
69- external : [
70- 'fs' ,
71- 'os' ,
72- 'util' ,
73- 'path' ,
74- 'http' ,
75- 'https' ,
76- 'handlebars/runtime' ,
77- ...external ,
78- ] ,
7978 plugins : getPlugins ( ) ,
8079} ;
0 commit comments