我正在尝试使用webpack从Angular项目代码的几个类中创建一个包。我只需要这些类,根本不需要使用装饰器。
捆绑包的最终结果非常大,因为类装饰器要加载很多依赖项。
例如main-bundler.ts
import { MyPipe } from 'some-location.pipe';
(<any>self).utils.MyPipe = MyPipe;
some-location.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ // <--- not needed and bloats the bundle
name: 'my-pipe'
})
export class MyPipe implements PipeTransform {
transform(value: any, args?: any): any {
return 'transformed value';
}
}
如果我选择注释管道,则文件大小从30632行减少到133行代码,这无疑节省了很多。有什么方法可以配置我的webpack配置以忽略角度项目中的装饰器及其依赖项?
my-webpack.config.js
const path = require('path');
const webpack = require('webpack');
const ROOT = path.resolve(__dirname, '../../src');
const DESTINATION = path.resolve(__dirname, '../../dist');
module.exports = {
mode: 'development',
context: ROOT,
entry: {
main: './main-bundler.ts',
},
output: {
filename: '[name].js',
path: __dirname + '/dist'
},
resolve: {
extensions: ['.ts', '.js'],
modules: [
ROOT,
'node_modules'
]
},
module: {
rules: [
/****************
* PRE-LOADERS
*****************/
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader'
},
{
enforce: 'pre',
test: /\.ts$/,
exclude: /node_modules/,
use: 'tslint-loader'
},
/****************
* LOADERS
*****************/
{
test: /\.ts$/,
exclude: [/node_modules/],
use: 'awesome-typescript-loader'
},
]
},
devtool: 'cheap-module-source-map',
devServer: {}
};