Commit 46eb3ae1 authored by 李苏's avatar 李苏 💬

1

parent 7550a7b8
const clearArrow = require('./tools/babel-clearArrow.js');
const proPlugins = ['dynamic-import-node']; const proPlugins = ['dynamic-import-node', [clearArrow]];
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
proPlugins.push('transform-remove-console'); proPlugins.push('transform-remove-console');
proPlugins.push('transform-remove-debugger');
} }
module.exports = { module.exports = {
presets: [ presets: [
...@@ -13,6 +14,9 @@ module.exports = { ...@@ -13,6 +14,9 @@ module.exports = {
// babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require(). // babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require().
// This plugin can significantly increase the speed of hot updates, when you have a large number of pages. // This plugin can significantly increase the speed of hot updates, when you have a large number of pages.
'plugins': proPlugins 'plugins': proPlugins
},
'production':{
'plugins': proPlugins
} }
} }
} }
module.exports = function (babel) {
/* 遍历AST时匹配visitor对象,遍历到FunctionDeclaration的节点会执行该回调*/
/* https://babeljs.io/docs/en/babel-types查看全部节点信息*/
const visitor = {
ArrowFunctionExpression(nodePath) {
/* 匹配到箭头函数时执行 */
/* 每一个方法都存在一个nodePath参数,所谓的nodePath参数你可以将它理解成为一个节点路径。它包含了这个树上这个节点分叉的所有信息和对应的api。注意这里可以强调是路径,你可以在这里查阅它的含义以及对应的所有API。*/
/* AST编译参考 https://astexplorer.net/*/
console.log('AST匹配到箭头函数',nodePath)
}
}
return {
visitor
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment