-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
68 lines (66 loc) · 1.62 KB
/
build.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { transform } from 'babel-core';
import * as babel from 'babel-core';
import fs from 'fs';
import path from 'path';
// import myImportCss from './myImportCss';
var myplugin=function({ types: t }) {
return {
visitor: {
Identifier(path, state) {},
BinaryExpression(path,state) {
if (path.node.operator !== "===") {
return;
}
path.node.left = t.identifier("sebmck");
path.node.right = t.identifier("dork");
}
}
};
};
var options={
babelrc:true,
parserOpts: {
"plugins": ["jsx", "flow"]
}
};
function tFile(){
babel.transformFile("./src/myImportCss.js", options, function (err, result) {
//console.log(result); // => { code, map, ast }
if(err){
console.log(err);
}
else{
fs.writeFileSync("./lib/myImportCss.js", result.code);
}
});
}
// babel.transform("import a from './app.css';", options,(err,result)=>{
// console.log("transform finish=======");
// if(err){
// console.log(err);
// }
// else{
// console.log(result.code);
// }
// });
// console.log("=============")
// console.log(result.code);
tFile();
// console.log(result);
// var a=require("babylon").parse("i=1;b=2;console.log(i+b);", {
// // parse in strict mode and allow module declarations
// sourceType: "module",
// plugins: [
// // enable jsx and flow syntax
// "jsx",
// "flow"
// ]
// });
// var a=result.ast;
// var out_str="";
// for(var i in a.tokens){
// if(a.tokens[i].value){
// out_str +=a.tokens[i].value;
// }
// }
// console.log(out_str);