-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (42 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* jshint asi:true */
var ECT = require( 'ect' )
var qs = require( 'qs' )
var assign = require('object.assign').getPolyfill()
var debug = require( 'debug' )( 'webpack:loader:ect' )
function generateOptions ( query ) {
return assign(
{
open: '<%',
close: '%>',
watch: false,
cache: false,
root: this.context
},
qs.parse(
( query + '' )
.replace( /^\?/ , '' )
)
)
}
module.exports = function ( source, map ) {
// Process query
options = generateOptions( this.query )
// Debug
debug( "Parsing %s with options: %s", this.resourcePath, JSON.stringify( options ) )
// Set this module as cacheable
this.cacheable()
// Create ect engine instance
var ect = ECT( options )
// Allways pass the source to a string
var template = source + ''
// Check if source should be minimized
if( this.minimized ) {
template = template
.replace( /\n/, ' ' )
.replace( /\s+/, ' ' )
}
// Parse source into a Function
var method = ect.compile( template )
// Return syncronously the javascript function generated
return 'module.exports = ' + method.toString()
}