HankLiu Vue Babel
提供基础的 vue babel 配置项
安装
npm install @hankliu/babel-vue -D
or
yarn add @hankliu/babel-vue -D
使用
- in .babelrc.js
const babelConfig = require('@hankliu/babel-vue');
// 修改规则
babelConfig.presets.push('@babel/preset-flow');
// if use antd
babelConfig.plugins.push(['import', { libraryName: 'antd', style: true }]);
babelConfig.plugins.push('@babel/plugin-transform-runtime');
module.exports = babelConfig;
- in webpack with babel-loader
{
rules: [{
test: /\.js(x*)$/,
loader: require.resolve('babel-loader'),
options: babelConfig
}]
}
注意
我们使用的是 peerDependencies 管理依赖,如果是在npm2中使用该插件,不许需要在自己项目中额外安装下列依赖,npm2会自行强制安装peerDependencies所要求指定的依赖包;如果是在npm3+中使用该插件,npm3中不会再要求peerDependencies所指定的依赖包被强制安装,相反npm3会在安装结束后检查本次安装是否正确,如果不正确会给用户打印警告提示。
"peerDependencies": {
"@babel/core": "^7.x",
"@babel/plugin-proposal-class-properties": "^7.x",
"@babel/plugin-proposal-decorators": "^7.x",
"@babel/plugin-syntax-dynamic-import": "^7.x",
"@babel/preset-env": "^7.x"
}