要将自定义的 Babel 插件添加到 Angular 7 的构建链中,你可以按照以下步骤进行操作:
npm install --save-dev @babel/core @babel/preset-env @babel/plugin-transform-arrow-functions
babel.config.js
的文件,并添加以下内容:module.exports = function (api) {
api.cache(true);
const presets = [
'@babel/preset-env'
];
const plugins = [
'@babel/plugin-transform-arrow-functions',
// 添加其他自定义的 Babel 插件
];
return {
presets,
plugins
};
}
angular.json
文件,在 projects -> -> architect -> build -> options
对象中找到 scripts
数组。将以下代码添加到 scripts
数组中:"scripts": [
{
"bundleName": "polyfills",
"input": "node_modules/@babel/preset-env/dist/polyfills.js"
}
]
tsconfig.json
文件,在 compilerOptions
对象中找到 plugins
数组。将以下代码添加到 plugins
数组中:"plugins": [
{
"name": "typescript-styled-plugin"
}
]
tsconfig.app.json
文件中,找到 compilerOptions
对象并添加以下代码:"plugins": [
{
"name": "typescript-styled-plugin"
}
]
ng build
命令,Angular 将使用你自定义的 Babel 插件来进行构建。以上步骤中的 @babel/plugin-transform-arrow-functions
只是一个示例插件,你可以将其替换为你自己的插件。确保在 babel.config.js
文件中添加所有需要的插件。