UNPKG

693 Btext/coffeescriptView Raw
1Mincer = require "mincer"
2
3module.exports = class RequireEngine extends Mincer.Template
4
5 @defaultMimeType: "application/javascript"
6
7 constructor: () ->
8 super
9
10 evaluate: (context) ->
11 define = "define"
12 name = context.logicalPath
13 data = this.data
14 index = data.indexOf(define)
15 if index != -1
16 before = data.substr(0, index)
17 data = data.substr(index)
18 data = data.substr(define.length) # define ([], function ()... -> ([], function () ...
19 data = data.trimLeft() # ([], function () ...
20 data = data.substr(1) # [], function () ...
21 data = before + define + "(\"#{name}\", " + data # ("name", [], function () ...
22 this.data = data
23