Skip to content

Commit

Permalink
Merge f3c520d into ae009b2
Browse files Browse the repository at this point in the history
  • Loading branch information
dansullivan86 committed Oct 18, 2016
2 parents ae009b2 + f3c520d commit 48cbf7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Expand Up @@ -39,6 +39,16 @@ define([], function() {
});
```

Transformed to **ES6** (`defineModule('es6')`):

```javascript
export default {
start: function() {},
end: function() {},
version: "1.0"
};
```

Transformed to **Hybrid** (`defineModule('hybrid')`):

```javascript
Expand Down Expand Up @@ -93,6 +103,7 @@ The desired output type. One of the following:
* `commonjs` - Produce CommonJS modules
* `node` - Produce Node modules (alias for `commonjs`)
* `amd` - Produce AMD modules
* `es6` - Produce ES6 modules
* `hybrid` - Produce hybrid modules that can be used in most environments
* `plain` - Return an unmolested function definition

Expand All @@ -103,7 +114,7 @@ Type: `Object`
Default: `{}`

An object containing dependencies that should be imported for this module. This option is only
supported for `commonjs`, `node`, `amd`, and `hybrid` modules. For other systems, you will have
supported for `commonjs`, `node`, `amd`, `es6` and `hybrid` modules. For other systems, you will have
to manage the dependency loading in another way.

The property name in the object should be the value of the variable that the
Expand All @@ -129,6 +140,12 @@ define(['library'], function(Library) {
});
```

**ES6**

```javascript
import Library from "library";
```

**Hybrid**

```javascript
Expand Down
10 changes: 10 additions & 0 deletions index.js
Expand Up @@ -52,6 +52,15 @@ function makeHybrid(moduleContents, filePath, opts) {
'})(function(' + defines.join(',') + ') { return ' + moduleContents + '; });';
}

function makeEs6(moduleContents, filePath, opts) {
var requires = _.map(opts.require, function(key, value) {
if (key !== null) {
return 'import ' + value + ' from ' + JSON.stringify(key) + ';';
}
});
return requires.join('') + 'export default ' + moduleContents + ';';
}

function makePlain(moduleContents, filePath, opts) {
// moduleObject;
return moduleContents + ';';
Expand Down Expand Up @@ -95,6 +104,7 @@ module.exports = function(type, options) {
else if (type === 'commonjs' || type === 'node') { contents = makeCommonJS(contents, file.path, opts); }
else if (type === 'hybrid') { contents = makeHybrid(contents, file.path, opts); }
else if (type === 'plain') { contents = makePlain(contents, file.path, opts); }
else if (type === 'es6') { contents = makeEs6(contents, file.path, opts); }
else {
throw new Error('Unsupported module type for gulp-define-module: ' + type);
}
Expand Down

0 comments on commit 48cbf7f

Please sign in to comment.