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' ;
13
10
14
11
/**
15
12
* Custom plugin to parse handlebar imports and precompile
@@ -18,15 +15,15 @@ const external = Object.keys(pkg.dependencies);
18
15
*/
19
16
const handlebarsPlugin = ( ) => ( {
20
17
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 ) ;
23
20
}
24
21
return null ;
25
22
} ,
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 , {
30
27
strict : true ,
31
28
noEscape : true ,
32
29
preventIndent : true ,
@@ -38,43 +35,45 @@ const handlebarsPlugin = () => ({
38
35
union : true ,
39
36
intersection : true ,
40
37
enumerator : true ,
41
- escapeQuotes : true ,
42
38
} ,
43
39
} ) ;
44
40
return `export default ${ templateSpec } ;` ;
45
41
}
46
42
return null ;
47
- }
43
+ } ,
48
44
} ) ;
49
45
50
46
const getPlugins = ( ) => {
51
47
const plugins = [
52
- handlebarsPlugin ( ) ,
53
- typescript ( ) ,
48
+ externals ( {
49
+ deps : true ,
50
+ } ) ,
54
51
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
+ ] ;
57
65
if ( process . env . NODE_ENV === 'development' ) {
58
66
return plugins ;
59
67
}
60
68
return [ ...plugins , terser ( ) ] ;
61
69
} ;
62
70
63
- module . exports = {
71
+ export default {
64
72
input : './src/index.ts' ,
65
73
output : {
74
+ exports : 'named' ,
66
75
file : './dist/index.js' ,
67
76
format : 'cjs' ,
68
77
} ,
69
- external : [
70
- 'fs' ,
71
- 'os' ,
72
- 'util' ,
73
- 'path' ,
74
- 'http' ,
75
- 'https' ,
76
- 'handlebars/runtime' ,
77
- ...external ,
78
- ] ,
79
78
plugins : getPlugins ( ) ,
80
79
} ;
0 commit comments