Skip to content

Commit

Permalink
use concat to wrap files with a UMD wrapper. Create sourceMap correct…
Browse files Browse the repository at this point in the history
…ly (#2206)
  • Loading branch information
caseyjhol committed Mar 8, 2019
1 parent 0a9d82d commit c5b57a0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
js/umd-intro.js
js/umd-outro.js
46 changes: 15 additions & 31 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,25 @@ module.exports = function (grunt) {

concat: {
options: {
stripBanners: true
stripBanners: true,
sourceMap: true
},
main: {
src: '<%= eslint.main.src %>',
dest: 'dist/js/<%= pkg.name %>.js'
src: 'js/<%= pkg.name %>.js',
dest: 'dist/js/<%= pkg.name %>.js',
options: {
banner: grunt.file.read('js/umd-intro.js'),
footer: grunt.file.read('js/umd-outro.js')
}
},
i18n: {
expand: true,
src: '<%= eslint.i18n.src %>',
dest: 'dist/'
}
},

umd: {
main: {
dest: 'dist/',
options: {
deps: {
'default': ['jQuery'],
amd: ['jquery'],
cjs: ['jquery'],
global: ['jQuery']
}
},
src: '<%= concat.main.dest %>'
},
i18n: {
options: {
deps: {
'default': ['jQuery'],
amd: ['jquery'],
cjs: ['jquery'],
global: ['jQuery']
}
},
src: 'dist/<%= eslint.i18n.src %>',
dest: '.'
banner: grunt.file.read('js/umd-intro.js'),
footer: grunt.file.read('js/umd-outro.js')
}
}
},

Expand All @@ -99,7 +82,8 @@ module.exports = function (grunt) {
dest: 'dist/js/<%= pkg.name %>.min.js',
options: {
sourceMap: true,
sourceMapName: 'dist/js/<%= pkg.name %>.js.map'
sourceMapIncludeSources: true,
sourceMapIn: 'dist/js/<%= pkg.name %>.js.map'
}
},
i18n: {
Expand Down Expand Up @@ -307,7 +291,7 @@ module.exports = function (grunt) {
grunt.registerTask('build-css', ['clean:css', 'less', 'autoprefixer', 'usebanner:css', 'cssmin']);

// JS distribution
grunt.registerTask('build-js', ['clean:js', 'eslint', 'concat', 'umd', 'uglify', 'usebanner:js']);
grunt.registerTask('build-js', ['clean:js', 'eslint', 'concat', 'uglify', 'usebanner:js']);

// Copy dist to docs
grunt.registerTask('docs', ['clean:docs', 'copy:docs']);
Expand Down
17 changes: 17 additions & 0 deletions js/umd-intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function (root, factory) {
if (root === undefined && window !== undefined) root = window;
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(["jquery"], function (a0) {
return (factory(a0));
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("jquery"));
} else {
factory(root["jQuery"]);
}
}(this, function (jQuery) {

3 changes: 3 additions & 0 deletions js/umd-outro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


}));
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"grunt-contrib-uglify": "^4.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^21.0.0",
"grunt-umd": "^3.0.0",
"grunt-version": "^1.1.1",
"load-grunt-tasks": "^4.0.0"
},
Expand Down

0 comments on commit c5b57a0

Please sign in to comment.