Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

proposal for #3: build different patterns independently

  • Loading branch information...
commit 839eb41da30fa7d2f1c5ab41213a5f897ce1a671 1 parent f71b4de
@jneen authored
View
31 Makefile
@@ -1,5 +1,7 @@
-SRC = src/p.js
-UGLY = build/p.min.js
+SRC_DIR = src
+BUILD_DIR = build
+SRC = $(SRC_DIR)/p.js
+UGLY = $(BUILD_DIR)/p.min.js
UGLIFYJS ?= uglifyjs
CLEAN += $(UGLY)
@@ -13,6 +15,29 @@ $(UGLY): $(SRC)
$(PRETTY): $(SRC)
$(UGLIFYJS) -b $(SRC) > $(UGLY)
+# special builds
+COMMONJS = $(BUILD_DIR)/p.commonjs.js
+COMMONJS_POST = src/p.commonjs_post.js
+CLEAN += $(COMMONJS)
+$(COMMONJS): $(SRC) $(COMMONJS_POST)
+ cat $(SRC) $(COMMONJS_POST) > $(COMMONJS)
+
+AMD = $(BUILD_DIR)/p.amd.js
+AMD_MIN = $(BUILD_DIR)/p.amd.min.js
+CLEAN += $(AMD) $(AMD_MIN)
+AMD_POST = src/p.amd_post.js
+$(AMD): $(SRC) $(AMD_POST)
+ cat $(SRC) $(AMD_POST) > $(AMD)
+
+$(AMD_MIN): $(AMD)
+ $(UGLIFYJS) $(AMD) > $(AMD_MIN)
+
+.PHONY: commonjs
+commonjs: $(COMMONJS)
+
+.PHONY: amd
+amd: $(AMD) $(AMD_MIN)
+
.PHONY: report
report: $(UGLY)
wc -c $(UGLY)
@@ -21,7 +46,7 @@ report: $(UGLY)
MOCHA ?= mocha
TESTS = ./test/*.test.js
.PHONY: test
-test: $(UGLY)
+test: $(COMMONJS)
$(MOCHA) $(TESTS)
# -*- packaging -*- #
View
2  index.js
@@ -1,2 +1,2 @@
-exports.P = require('./src/p').P;
+exports.P = require('./build/p.commonjs').P;
exports.version = JSON.parse(require('fs').readFileSync(__dirname + '/package.json')).version;
View
1  package.json
@@ -12,6 +12,7 @@
"mocha": "0.8.1"
},
"scripts": {
+ "install": "make commonjs",
"test": "make test"
}
}
View
1  src/amd_post.js
@@ -0,0 +1 @@
+define({P: P});
View
1  src/p.amd_post.js
@@ -0,0 +1 @@
+define(P);
View
1  src/p.commonjs_post.js
@@ -0,0 +1 @@
+exports.P = P;
View
2  src/p.js
@@ -44,5 +44,3 @@ var P = (function(slice, prototype, hasOwnProperty, undefined) {
return P;
})([].slice, 'prototype', ({}).hasOwnProperty);
-
-if (typeof exports !== 'undefined') exports.P = P
Please sign in to comment.
Something went wrong with that request. Please try again.