Last active
December 18, 2015 05:59
-
-
Save thomasboyt/5736652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| concat: { | |
| amd: { | |
| src: "tmp/**/*.amd.js", | |
| dest: "dist/my_library.amd.js" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| transpile: { | |
| amd: { | |
| type: 'amd', | |
| files: [{ | |
| expand: true, | |
| cwd: 'lib/', | |
| src: ['**/*.js'], | |
| dest: 'tmp/', | |
| ext: '.amd.js' | |
| }] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| grunt.registerMultiTask('browser', "Export a module to the window", function() { | |
| var opts = this.options(); | |
| this.files.forEach(function(f) { | |
| var output = ["(function(globals) {"]; | |
| output.push.apply(output, f.src.map(grunt.file.read)); | |
| output.push(grunt.template.process( | |
| 'window.<%= namespace %> = requireModule("<%= barename %>");', { | |
| data: { | |
| namespace: opts.namespace, | |
| barename: opts.barename | |
| } | |
| })); | |
| output.push('})(window);'); | |
| grunt.file.write(f.dest, grunt.template.process(output.join("\n"))); | |
| }); | |
| }); | |
| // ... | |
| grunt.initConfig({ | |
| // ... | |
| browser: { | |
| dist: { | |
| src: ["vendor/loader.js", "dist/my_library.amd.js"], | |
| dest: "dist/my_library.js", | |
| options: { | |
| barename: "my_library", | |
| namespace: "MyLibrary" | |
| } | |
| } | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| transpile: { | |
| // ... | |
| commonjs: { | |
| type: 'cjs', | |
| files: [{ | |
| expand: true, | |
| cwd: 'lib/', | |
| src: ['my_library/*.js'], | |
| dest: 'dist/commonjs/', | |
| ext: '.js' | |
| }, | |
| { | |
| src: ['lib/my_library.js'], | |
| dest: 'dist/commonjs/main.js' | |
| }] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function(grunt) { | |
| grunt.loadNpmTasks("grunt-es6-module-transpiler"); | |
| grunt.loadNpmTasks("grunt-contrib-concat"); | |
| grunt.initConfig({ | |
| transpile: { | |
| amd: { | |
| type: 'amd', | |
| files: [{ | |
| expand: true, | |
| cwd: 'lib/', | |
| src: ['**/*.js'], | |
| dest: 'tmp/', | |
| ext: '.amd.js' | |
| }] | |
| }, | |
| commonjs: { | |
| type: 'cjs', | |
| files: [{ | |
| expand: true, | |
| cwd: 'lib/', | |
| src: ['my_library/*.js'], | |
| dest: 'dist/commonjs/', | |
| ext: '.js' | |
| }, | |
| { | |
| src: ['lib/my_library.js'], | |
| dest: 'dist/commonjs/main.js' | |
| }] | |
| } | |
| }, | |
| concat: { | |
| amd: { | |
| src: "tmp/**/*.amd.js", | |
| dest: "dist/my_library.amd.js" | |
| }, | |
| browser: { | |
| src: ["vendor/loader.js", "dist/my_library.amd.js"], | |
| dest: "dist/my_library.js" | |
| } | |
| } | |
| }); | |
| grunt.registerTask("default", ["transpile", "concat"]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { shout } from "./my_library/shout"; | |
| import { ssshh } from "./my_library/ssshh"; | |
| export { shout, ssshh }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "my-library", | |
| "main": "dist/commonjs/main.js" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var shout = function(s) { | |
| return s.toUpperCase(); | |
| } | |
| export shout; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ssshh = function(s) { | |
| return s.toLowerCase(); | |
| } | |
| export ssshh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
running grunt transpile:commonjs has the error as follow:
line 5 should be revised as
export { shout }, and then grunt running successed.