Permalink
Browse files

Got example optimizer runs working

  • Loading branch information...
1 parent 2d69ee7 commit 7561347fcdea832dab17fc9e06875b285f1456b5 @jrburke committed Jun 30, 2012
View
@@ -66,7 +66,14 @@ is sufficient:
Circular references that do import * on each other will not work.
-3) Using identifiers for "inline modules" is not supported:
+3) import * does not work in build
+
+Using r.js to optimize a set of hm modules to a concatenated list of AMD
+modules works for everything except import *, since the build does not actually
+run the * module as part of the build, since it may accesss environment-specific
+information, like `window` or `navigator` which do not exist in Node.
+
+4) Using identifiers for "inline modules" is not supported:
module Bar {}
@@ -108,6 +115,18 @@ require(['hm!main'], function (main) {
});
```
+## Doing Builds
+
+See `tests/build` for example build files (the X.build.js files).
+
+The AMD version of the modules are placed in the built file, so the `hm` and
+`esprima` modules do not need to be included in the build file.
+
+See the build files for more details.
+
+If any .hm files will be loaded dynamically after a build, then the source
+versions of `hm` and `esprima` should stay in the build.
+
## Running Tests
### In Browser
View
@@ -40,12 +40,12 @@ parseStatement: true, parseSourceElement: true, parseModuleBlock: true, parseCon
(function (factory) {
'use strict';
- if (typeof exports !== 'undefined') {
- // Node/CommonJS
- factory(exports);
- } else if (typeof define === 'function' && define.amd) {
+ if (typeof define === 'function' && define.amd) {
// AMD
define(['exports'], factory);
+ } else if (typeof exports !== 'undefined') {
+ // Node/CommonJS
+ factory(exports);
} else {
// Browser globals
factory((esprima = {}));
@@ -0,0 +1,48 @@
+
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
+define('hm!funcs',['require','exports','module'],function (require, exports, module) {
+var oneName = 'one';
+
+exports.one = function () {
+ return oneName;
+};
+
+exports._helloWorld = function (value){
+ return 'hello ' + value
+ };
+
+
+});
+define('hm!vars',['require','exports','module'],function (require, exports, module) {
+
+exports.foo =
+ 'foo';
+
+exports.bar = 'bar'
+
+});
+require({
+ baseUrl: require.isBrowser ? '.' : 'export',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ }
+});
+
+require(["hm!funcs", "hm!vars"],
+function (funcs, vars) {
+ doh.register(
+ "exportTests",
+ [
+ function exportTests(t){
+ t.is("one", funcs.one());
+ t.is("hello des moines", funcs._helloWorld('des moines'));
+ t.is("foo", vars.foo);
+ t.is("bar", vars.bar);
+ }
+ ]
+ );
+ doh.run();
+});
+
+define("export-tests", function(){});
@@ -0,0 +1,48 @@
+
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
+define('hm!funcs',['require','exports','module'],function (require, exports, module) {
+var oneName = 'one';
+
+exports.one = function () {
+ return oneName;
+};
+
+exports._helloWorld = function (value){
+ return 'hello ' + value
+ };
+
+
+});
+define('hm!vars',['require','exports','module'],function (require, exports, module) {
+
+exports.foo =
+ 'foo';
+
+exports.bar = 'bar'
+
+});
+require({
+ baseUrl: require.isBrowser ? '.' : 'export',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ }
+});
+
+require(["hm!funcs", "hm!vars"],
+function (funcs, vars) {
+ doh.register(
+ "exportTests",
+ [
+ function exportTests(t){
+ t.is("one", funcs.one());
+ t.is("hello des moines", funcs._helloWorld('des moines'));
+ t.is("foo", vars.foo);
+ t.is("bar", vars.bar);
+ }
+ ]
+ );
+ doh.run();
+});
+
+define("export-tests", function(){});
@@ -0,0 +1,17 @@
+{
+ baseUrl: '../export',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ },
+ name: 'export-tests',
+ //Do not need esprima after the build.
+ exclude: ['esprima'],
+ out: 'export-tests-built.js',
+ optimize: 'none',
+ //Stub out hm the build. Need to keep
+ //the plugin stub in the build since
+ //loader will want to check it for any
+ //normalize method.
+ stubModules: ['hm']
+}
@@ -0,0 +1,61 @@
+
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
+define('hm!gamma',['require','exports','module'],function (require, exports, module) {
+
+exports.name = 'gamma';
+
+});
+define('hm!beta',['require','exports','module'],function (require, exports, module) {
+
+// Simple module and a text comment that mentions module
+exports.name = 'beta';
+
+exports.func = function () {
+ return 'beta function';
+}
+
+exports.uniqueBeta = 'uniqueBeta';
+
+});
+define('hm!alpha',['require','exports','module','hm!gamma','hm!beta','hm!beta','hm!beta'],function (require, exports, module) {
+
+var gamma = require("hm!gamma");
+
+var gammaName = gamma.name;
+var betaName = require("hm!beta").name;
+var betaFunc = require("hm!beta").func;
+var uniqueBeta = require("hm!beta").uniqueBeta;
+exports.gammaName = gammaName;
+
+exports.betaName = betaName;
+
+exports.betaFunc = betaFunc;
+
+exports.uniqueBeta = uniqueBeta;
+
+});
+require({
+ baseUrl: require.isBrowser ? '.' : 'import',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ }
+});
+
+require(["hm!alpha"],
+function (alpha) {
+ doh.register(
+ "importTests",
+ [
+ function importTests(t){
+ t.is("gamma", alpha.gammaName);
+ t.is("beta", alpha.betaName);
+ t.is("beta function", alpha.betaFunc());
+ t.is("uniqueBeta", alpha.uniqueBeta);
+ }
+ ]
+ );
+ doh.run();
+});
+
+define("import-tests", function(){});
@@ -0,0 +1,61 @@
+
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
+define('hm!gamma',['require','exports','module'],function (require, exports, module) {
+
+exports.name = 'gamma';
+
+});
+define('hm!beta',['require','exports','module'],function (require, exports, module) {
+
+// Simple module and a text comment that mentions module
+exports.name = 'beta';
+
+exports.func = function () {
+ return 'beta function';
+}
+
+exports.uniqueBeta = 'uniqueBeta';
+
+});
+define('hm!alpha',['require','exports','module','hm!gamma','hm!beta','hm!beta','hm!beta'],function (require, exports, module) {
+
+var gamma = require("hm!gamma");
+
+var gammaName = gamma.name;
+var betaName = require("hm!beta").name;
+var betaFunc = require("hm!beta").func;
+var uniqueBeta = require("hm!beta").uniqueBeta;
+exports.gammaName = gammaName;
+
+exports.betaName = betaName;
+
+exports.betaFunc = betaFunc;
+
+exports.uniqueBeta = uniqueBeta;
+
+});
+require({
+ baseUrl: require.isBrowser ? '.' : 'import',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ }
+});
+
+require(["hm!alpha"],
+function (alpha) {
+ doh.register(
+ "importTests",
+ [
+ function importTests(t){
+ t.is("gamma", alpha.gammaName);
+ t.is("beta", alpha.betaName);
+ t.is("beta function", alpha.betaFunc());
+ t.is("uniqueBeta", alpha.uniqueBeta);
+ }
+ ]
+ );
+ doh.run();
+});
+
+define("import-tests", function(){});
@@ -0,0 +1,17 @@
+{
+ baseUrl: '../import',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ },
+ name: 'import-tests',
+ //Do not need esprima after the build.
+ exclude: ['esprima'],
+ out: 'import-tests-built.js',
+ optimize: 'none',
+ //Stub out hm the build. Need to keep
+ //the plugin stub in the build since
+ //loader will want to check it for any
+ //normalize method.
+ stubModules: ['hm']
+}
@@ -0,0 +1,70 @@
+
+define('hm',{load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
+define('hm!theta',['require','exports','module'],function (require, exports, module) {
+
+exports.thetaOne = 'thetaOne'
+exports.thetaTwo = 'thetaTwo'
+
+});
+define('hm!sigma',['require','exports','module'],function (require, exports, module) {
+
+var sigmaNumber = 4;
+
+function sigmaFunc() {
+ return 'sigma function';
+}
+
+exports.sigmaNumber = sigmaNumber;
+exports.sigmaFunc = sigmaFunc;
+
+});
+define('hm!epsilon',['require','exports','module'],function (require, exports, module) {
+
+/*
+Fake comment to try to break the hm parser.
+module bad = 'bad';
+*/
+
+//import {bad2} from 'bad2'
+
+
+
+exports.thetaOne = thetaOne;
+
+exports.thetaTwo = thetaTwo;
+
+exports.sigmaFunc = sigmaFunc;
+
+exports.sigmaNumber = sigmaNumber;
+
+});
+require({
+ baseUrl: require.isBrowser ? '.' : 'import',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ },
+ config: {
+ hm: {
+ logTransform: require.isBrowser
+ }
+ }
+});
+
+require(["hm!epsilon"],
+function (epsilon) {
+ doh.register(
+ "importStarTests",
+ [
+ function importStarTests(t){
+ t.is("thetaOne", epsilon.thetaOne);
+ t.is("thetaTwo", epsilon.thetaTwo);
+ t.is("sigma function", epsilon.sigmaFunc());
+ t.is("4", epsilon.sigmaNumber);
+ }
+ ]
+ );
+ doh.run();
+});
+
+define("importstar-tests", function(){});
@@ -0,0 +1,17 @@
+{
+ baseUrl: '../import',
+ paths: {
+ hm: '../../hm',
+ esprima: '../../esprima'
+ },
+ name: 'importstar-tests',
+ //Do not need esprima after the build.
+ exclude: ['esprima'],
+ out: 'importstar-tests-built.js',
+ optimize: 'none',
+ //Stub out hm the build. Need to keep
+ //the plugin stub in the build since
+ //loader will want to check it for any
+ //normalize method.
+ stubModules: ['hm']
+}
Oops, something went wrong.

0 comments on commit 7561347

Please sign in to comment.