File tree Expand file tree Collapse file tree 4 files changed +27
-8
lines changed
Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -11,22 +11,30 @@ const yargs = require('yargs')
1111 type : 'string' ,
1212 description : 'Source Map File'
1313 } )
14- . option ( 'a' , {
15- type : 'boolean' ,
16- description : 'Exports amd style (require.js)' ,
17- alias : 'amd'
14+ . option ( 'esm' , {
15+ type : 'string' ,
16+ description :
17+ 'Exports ECMAScript module style, path to Handlebars module (eg. "handlebars/lib/handlebars")' ,
18+ default : null
1819 } )
1920 . option ( 'c' , {
2021 type : 'string' ,
2122 description : 'Exports CommonJS style, path to Handlebars module' ,
2223 alias : 'commonjs' ,
2324 default : null
2425 } )
26+ . option ( 'a' , {
27+ type : 'boolean' ,
28+ description : 'Exports AMD style (require.js)' ,
29+ alias : 'amd' ,
30+ deprecated : true
31+ } )
2532 . option ( 'h' , {
2633 type : 'string' ,
27- description : 'Path to handlebar.js (only valid for amd -style)' ,
34+ description : 'Path to handlebar.js (only valid for AMD -style)' ,
2835 alias : 'handlebarPath' ,
29- default : ''
36+ default : '' ,
37+ deprecated : true
3038 } )
3139 . option ( 'k' , {
3240 type : 'string' ,
Original file line number Diff line number Diff line change @@ -206,6 +206,8 @@ module.exports.cli = function(opts) {
206206 ) ;
207207 } else if ( opts . commonjs ) {
208208 output . add ( 'var Handlebars = require("' + opts . commonjs + '");' ) ;
209+ } else if ( opts . esm ) {
210+ output . add ( `import handlebars from "${ opts . esm } ";` ) ;
209211 } else {
210212 output . add ( '(function() {\n' ) ;
211213 }
Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ Options:
55 --help Outputs this message [boolean]
66 -f, --output Output File [string]
77 --map Source Map File [string]
8- -a, --amd Exports amd style (require.js) [boolean]
8+ --esm Exports ECMAScript module style, path to Handlebars module (eg. "handlebars/lib/handlebars")
9+ [string] [default: null]
910 -c, --commonjs Exports CommonJS style, path to Handlebars module [string] [default: null]
10- -h, --handlebarPath Path to handlebar.js (only valid for amd-style) [string] [default: ""]
11+ -a, --amd Exports AMD style (require.js) [deprecated] [boolean]
12+ -h, --handlebarPath Path to handlebar.js (only valid for AMD-style) [deprecated] [string] [default: ""]
1113 -k, --known Known helpers [string]
1214 -o, --knownOnly Known helpers only [boolean]
1315 -m, --min Minimize output [boolean]
Original file line number Diff line number Diff line change @@ -197,6 +197,13 @@ describe('precompiler', function() {
197197 equal ( / r e t u r n H a n d l e b a r s \. p a r t i a l s \[ / . test ( log ) , false ) ;
198198 equal ( / t e m p l a t e \( a m d \) / . test ( log ) , true ) ;
199199 } ) ;
200+ it ( 'should output es module templates' , function ( ) {
201+ Handlebars . precompile = function ( ) {
202+ return 'esm' ;
203+ } ;
204+ Precompiler . cli ( { templates : [ emptyTemplate ] , esm : true } ) ;
205+ equal ( / t e m p l a t e \( e s m \) / . test ( log ) , true ) ;
206+ } ) ;
200207 it ( 'should output commonjs templates' , function ( ) {
201208 Handlebars . precompile = function ( ) {
202209 return 'commonjs' ;
You can’t perform that action at this time.
0 commit comments