Compare commits
1 Commits
master
...
precompile-esm
| Author | SHA1 | Date | |
|---|---|---|---|
| 88f789e419 |
+13
-5
@@ -11,10 +11,11 @@ const yargs = require('yargs')
|
||||
type: 'string',
|
||||
description: 'Source Map File',
|
||||
})
|
||||
.option('a', {
|
||||
type: 'boolean',
|
||||
description: 'Exports amd style (require.js)',
|
||||
alias: 'amd',
|
||||
.option('esm', {
|
||||
type: 'string',
|
||||
description:
|
||||
'Exports ECMAScript module style, path to Handlebars module (eg. "handlebars/lib/handlebars")',
|
||||
default: null,
|
||||
})
|
||||
.option('c', {
|
||||
type: 'string',
|
||||
@@ -22,11 +23,18 @@ const yargs = require('yargs')
|
||||
alias: 'commonjs',
|
||||
default: null,
|
||||
})
|
||||
.option('a', {
|
||||
type: 'boolean',
|
||||
description: 'Exports AMD style (require.js)',
|
||||
alias: 'amd',
|
||||
deprecated: true,
|
||||
})
|
||||
.option('h', {
|
||||
type: 'string',
|
||||
description: 'Path to handlebar.js (only valid for amd-style)',
|
||||
description: 'Path to handlebar.js (only valid for AMD-style)',
|
||||
alias: 'handlebarPath',
|
||||
default: '',
|
||||
deprecated: true,
|
||||
})
|
||||
.option('k', {
|
||||
type: 'string',
|
||||
|
||||
@@ -209,6 +209,8 @@ module.exports.cli = function (opts) {
|
||||
);
|
||||
} else if (opts.commonjs) {
|
||||
output.add('var Handlebars = require("' + opts.commonjs + '");');
|
||||
} else if (opts.esm) {
|
||||
output.add(`import handlebars from "${opts.esm}";`);
|
||||
} else {
|
||||
output.add('(function() {\n');
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ Options:
|
||||
--help Outputs this message [boolean]
|
||||
-f, --output Output File [string]
|
||||
--map Source Map File [string]
|
||||
-a, --amd Exports amd style (require.js) [boolean]
|
||||
--esm Exports ECMAScript module style, path to Handlebars module (eg. "handlebars/lib/handlebars")
|
||||
[string] [default: null]
|
||||
-c, --commonjs Exports CommonJS style, path to Handlebars module [string] [default: null]
|
||||
-h, --handlebarPath Path to handlebar.js (only valid for amd-style) [string] [default: ""]
|
||||
-a, --amd Exports AMD style (require.js) [deprecated] [boolean]
|
||||
-h, --handlebarPath Path to handlebar.js (only valid for AMD-style) [deprecated] [string] [default: ""]
|
||||
-k, --known Known helpers [string]
|
||||
-o, --knownOnly Known helpers only [boolean]
|
||||
-m, --min Minimize output [boolean]
|
||||
|
||||
@@ -197,6 +197,13 @@ describe('precompiler', function () {
|
||||
equal(/return Handlebars\.partials\[/.test(log), false);
|
||||
equal(/template\(amd\)/.test(log), true);
|
||||
});
|
||||
it('should output es module templates', function () {
|
||||
Handlebars.precompile = function () {
|
||||
return 'esm';
|
||||
};
|
||||
Precompiler.cli({ templates: [emptyTemplate], esm: true });
|
||||
equal(/template\(esm\)/.test(log), true);
|
||||
});
|
||||
it('should output commonjs templates', function () {
|
||||
Handlebars.precompile = function () {
|
||||
return 'commonjs';
|
||||
|
||||
Reference in New Issue
Block a user