问题
angular升级后,推荐使用angular-cli创建打包项目,但是有特殊的需求是就显然不是很灵活。
例如,团队之前要求前端项目都build成zip包,webpack配置倒是挺简单,问题是angular封装了webpack后,不知道在哪里能增加配置
解决办法
好在angular还是提供了外挂一样的方式。
--extra-webpack-config
增加npm依赖
ngx-build-plus
这个参数可以额外指定一个webpack config 文件
使用方式
webpack config文件内容
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin') ;
var ZipPlugin = require('zip-webpack-plugin')
module.exports = {
plugins: [
new HtmlWebpackPlugin({
filename: 'download.html',
excludeChunks: ['main','runtime','styles','polyfills'],
template: './src/download.html',
title: 'test Title'
}),
new ZipPlugin({
path:path.join(__dirname,'zip'),
filename: 'test.zip',
// pathPrefix: 'zip',
}),
],
}