diff --git a/examples/example.js b/examples/example.js index 7fad25b..be25fca 100644 --- a/examples/example.js +++ b/examples/example.js @@ -58,7 +58,7 @@ return this.require; }).call(this); -this.require.define({"modules/program":function(exports, require, module){module.exports = function(){ +this.require.define({"modules/program.cjs":function(exports, require, module){module.exports = function(){ alert('Long live the Programs!'); }; ;}}); diff --git a/examples/modules/program.module.js b/examples/modules/program.cjs.js similarity index 100% rename from examples/modules/program.module.js rename to examples/modules/program.cjs.js diff --git a/lib/sprockets/commonjs.rb b/lib/sprockets/commonjs.rb index 09e3509..ed73299 100644 --- a/lib/sprockets/commonjs.rb +++ b/lib/sprockets/commonjs.rb @@ -4,11 +4,13 @@ module Sprockets class CommonJS < Tilt::Template - DEFINE_WRAPPER = '%s.define({%s:' + + WRAPPER = '%s.define({%s:' + 'function(exports, require, module){' + '%s' + ";}});\n" + EXTENSIONS = %w{.module .cjs} + class << self attr_accessor :default_namespace end @@ -36,7 +38,7 @@ def evaluate(scope, locals, &block) attr_reader :namespace def commonjs_module?(scope) - File.extname(scope.logical_path) == '.module' + EXTENSIONS.include?(File.extname(scope.logical_path)) end def module_name(scope)