forked from s0ber/static-file-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (20 loc) · 800 Bytes
/
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
var fileLoader = require('file-loader')
var path = require('path')
var urlJoin = require('url-join')
var MAP_KEY = '__static_loader_map__'
module.exports = function (content) {
var originEmitFile = this.emitFile
var map = this._compilation[MAP_KEY] = this._compilation[MAP_KEY] || {}
// Override emitFile function to get an url from file-loader
this.emitFile = function (url, fileContent) {
map[this.resource] = urlJoin((this.options || this._compiler.options).output.publicPath || '/', url)
originEmitFile.call(this, url, fileContent)
}.bind(this)
// Call file-loader and store the result
var result = fileLoader.call(this, content)
// Restore emitFile function
this.emitFile = originEmitFile
return result
}
module.exports.raw = true
module.exports.key = MAP_KEY