Skip to content

Commit

Permalink
Remove amd files from the build
Browse files Browse the repository at this point in the history
Users can utilize the UMD library if they are still using require.js and if they need to have specific modules, they can consume the cjs or es6 modules via webpack or similar.

Fix for #1096
  • Loading branch information
kpdecker committed Dec 14, 2015
1 parent 63fdb92 commit 8517352
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 283 deletions.
10 changes: 1 addition & 9 deletions FAQ.md
Expand Up @@ -47,14 +47,6 @@

Should these match, please file an issue with us, per our [issue filing guidelines](https://github.com/wycats/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).

1. Why doesn't IE like the `default` name in the AMD module?

Some browsers such as particular versions of IE treat `default` as a reserved word in JavaScript source files. To safely use this you need to reference this via the `Handlebars['default']` lookup method. This is an unfortunate side effect of the shims necessary to backport the Handlebars ES6 code to all current browsers.

1. How do I load the runtime library when using AMD?

There are two options for loading under AMD environments. The first is to use the `handlebars.runtime.amd.js` file. This may require a [path mapping](https://github.com/wycats/handlebars.js/blob/master/spec/amd-runtime.html#L31) as well as access via the `default` field.

The other option is to load the `handlebars.runtime.js` UMD build, which might not require path configuration and exposes the library as both the module root and the `default` field for compatibility.

If not using ES6 transpilers or accessing submodules in the build the former option should be sufficient for most use cases.
The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility.
47 changes: 5 additions & 42 deletions Gruntfile.js
Expand Up @@ -44,23 +44,6 @@ module.exports = function(grunt) {
},

babel: {
options: {
sourceMaps: 'inline',
loose: ['es6.modules'],
auxiliaryCommentBefore: 'istanbul ignore next'
},
amd: {
options: {
modules: 'amd'
},
files: [{
expand: true,
cwd: 'lib/',
src: '**/!(index).js',
dest: 'dist/amd/'
}]
},

cjs: {
options: {
modules: 'common'
Expand Down Expand Up @@ -102,25 +85,6 @@ module.exports = function(grunt) {
}
},

requirejs: {
options: {
optimize: 'none',
baseUrl: 'dist/amd/'
},
dist: {
options: {
name: 'handlebars',
out: 'dist/handlebars.amd.js'
}
},
runtime: {
options: {
name: 'handlebars.runtime',
out: 'dist/handlebars.runtime.amd.js'
}
}
},

uglify: {
options: {
mangle: true,
Expand Down Expand Up @@ -160,7 +124,7 @@ module.exports = function(grunt) {
all: {
options: {
build: process.env.TRAVIS_JOB_ID,
urls: ['http://localhost:9999/spec/?headless=true', 'http://localhost:9999/spec/amd.html?headless=true'],
urls: ['http://localhost:9999/spec/?headless=true'],
detailedError: true,
concurrency: 4,
browsers: [
Expand All @@ -176,11 +140,12 @@ module.exports = function(grunt) {
sanity: {
options: {
build: process.env.TRAVIS_JOB_ID,
urls: ['http://localhost:9999/spec/umd.html?headless=true', 'http://localhost:9999/spec/amd-runtime.html?headless=true', 'http://localhost:9999/spec/umd-runtime.html?headless=true'],
urls: ['http://localhost:9999/spec/umd.html?headless=true', 'http://localhost:9999/spec/umd-runtime.html?headless=true'],
detailedError: true,
concurrency: 2,
browsers: [
{browserName: 'chrome'}
{browserName: 'chrome'},
{browserName: 'internet explorer', version: 10, platform: 'Windows 8'}
]
}
}
Expand All @@ -205,19 +170,17 @@ module.exports = function(grunt) {
'node',
'globals']);

this.registerTask('amd', ['babel:amd', 'requirejs']);
this.registerTask('node', ['babel:cjs']);
this.registerTask('globals', ['webpack']);
this.registerTask('tests', ['concat:tests']);

this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);
this.registerTask('release', 'Build final packages', ['eslint', 'uglify', 'test:min', 'copy:dist', 'copy:components', 'copy:cdnjs']);

// Load tasks from npm
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-babel');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -42,7 +42,6 @@
"grunt-contrib-concat": "0.x",
"grunt-contrib-connect": "0.x",
"grunt-contrib-copy": "0.x",
"grunt-contrib-requirejs": "0.x",
"grunt-contrib-uglify": "0.x",
"grunt-contrib-watch": "0.x",
"grunt-eslint": "^17.1.0",
Expand All @@ -68,7 +67,7 @@
"jspm": {
"main": "handlebars",
"directories": {
"lib": "dist/amd"
"lib": "dist/cjs"
},
"buildConfig": {
"minify": true
Expand Down
105 changes: 0 additions & 105 deletions spec/amd-runtime.html

This file was deleted.

125 changes: 0 additions & 125 deletions spec/amd.html

This file was deleted.

0 comments on commit 8517352

Please sign in to comment.