-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
35 lines (30 loc) · 834 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
28
29
30
31
32
33
34
35
const pkg = require('./package.json');
const supportExt = ['.js', '.css']
module.exports = function (snowpackConfig, pluginOptions) {
return {
name: pkg.name,
transform({ id, contents, fileExt }) {
if(!supportExt.includes(fileExt)) {
// Skip not support version
return contents;
}
const list = pluginOptions.list || [];
for (let item of list) {
const file = item.file;
if(typeof file === 'string') {
// If specify file path. check it
if(file !== id) {
continue;
}
}
let str = item.from;
if(str === undefined || str === null) {
continue;
}
const replaceValue = item.to;
contents = contents.replace(str, replaceValue);
}
return contents;
},
};
};