如何在为生产构建时禁用Angular 7代码损坏?
我想在为Angular 7应用程序进行生产构建时禁用代码损坏 现在的问题是,当我尝试在构建应用程序后启动应用程序时,我出现了一个错误:如何在为生产构建时禁用Angular 7代码损坏?,angular,webpack,build,uglifyjs,Angular,Webpack,Build,Uglifyjs,我想在为Angular 7应用程序进行生产构建时禁用代码损坏 现在的问题是,当我尝试在构建应用程序后启动应用程序时,我出现了一个错误: Error: [$injector:unpr] Unknown provider: e 我认为这是因为喷油器在缩小后无法识别供应商名称。我想关闭代码混乱可以解决这个问题。但是,在Angular 7中,我不能使用webpack eject更改默认的webpack配置。我使用@angular builders/custom webpack:browser添加我自己
Error: [$injector:unpr] Unknown provider: e
我认为这是因为喷油器在缩小后无法识别供应商名称。我想关闭代码混乱可以解决这个问题。但是,在Angular 7中,我不能使用webpack eject
更改默认的webpack配置。我使用@angular builders/custom webpack:browser
添加我自己的网页配置,将其合并到默认设置。然后我尝试设置UglifyJsPlugin
的设置,关闭损坏:
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const nibStylusPlugin = require('nib');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const nodeEnvironment = process.env.NODE_ENV || 'development';
const appConfig = process.env.APP_CONFIG || 'testing';
console.info("[INFO] NodeJS environment in webpack: " + nodeEnvironment);
console.info("[INFO] Used configuration in webpack: " + appConfig);
module.exports = {
target: 'web',
context: path.resolve(__dirname, 'ng1App'),
resolve: {
extensions: ['.ts', '.js', '.tsx', '.json']
},
module: {
rules: [
{
test: /\.pug$/,
use: [{
loader: 'ng-cache-loader?module=views&prefix=app:**', // ng-cache-loader doesn't understand new syntax
}, {
loader: 'pug-html-loader',
options: {
pretty: false,
exports: false,
doctype: 'html'
}
}]
}, // end pug
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ng-annotate-loader',
options: {
es6: true
}
},
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
},
{
loader: 'tslint-loader',
options: {
emitErrors: false,
failOnHint: false
}
}]
}, // end typescript
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?(\?[0-9]+)?$/,
use: ['file-loader']
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?(\?[0-9]+)?$/,
use: ['file-loader']
},
{
test: /\.jpe?g$|\.ico$|\.gif$|\.png$|\.wav$|\.mp3$/,
loader: 'file-loader?name=[name].[ext]' // <-- retain original file name
},
]
},
plugins: [
new ForkTsCheckerWebpackPlugin({tsconfig: '../tsconfig.json', workers: ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE }),
new CopyWebpackPlugin([
{ from: `../dist_config/${appConfig}.config.json`, to: 'config.json' },
{ from: 'assets', to: 'assets' },
{ from: 'favicon.ico', to: 'favicon.ico' },
]),
new MiniCssExtractPlugin({
filename: "[name].css"
}),
// provide global variables in each file - this allows to use them directly without importing. Below variables are exported by vendors
// below code is an example on how to tell webpack to treat some variable as a global, and provide it through code
new webpack.ProvidePlugin({
"window.jQuery": "jquery",
tv4: "tv4"
}),
new webpack.LoaderOptionsPlugin({
options: {
stylus: {
use: [nibStylusPlugin()],
import: ['~nib/lib/nib/index.styl'],
}
}
}),
// new BundleAnalyzerPlugin({generateStatsFile: true}) // comment out to launch bundle analyzer after the build is finished
],
optimization: {
minimizer: [new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
parse: {},
compress: {},
mangle: false, // Note `mangle.properties` is `false` by default.
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_fnames: true,
},
})],
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'all',
name: 'vendor',
reuseExistingChunk: true,
test: /[\\/]node_modules[\\/]/,
priority: -10
}
}
}
},
devServer: {
contentBase: path.join(__dirname, 'dist_config'),
proxy: {
'/config.json': {
target: 'http://localhost:4200/' + appConfig + '.config.json',
pathRewrite: {'^/config.json' : ''}
}
},
open: true,
port: 4200,
historyApiFallback: true,
compress: true,
watchOptions: {
aggregateTimeout: 200,
ignored: /node_modules/
}
},
node: {
global: true,
process: true,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
const path=require('path');
const MiniCssExtractPlugin=require(“迷你css提取插件”);
const nibStylusPlugin=require('nib');
const ForkTsCheckerWebpackPlugin=require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin=require('copy-webpack-plugin');
const webpack=require('webpack');
const BundleAnalyzerPlugin=require('webpack-bundle-analyzer')。BundleAnalyzerPlugin;
const UglifyJsPlugin=require('uglifyjs-webpack-plugin');
const nodeEnvironment=process.env.NODE|u env||'development';
const appConfig=process.env.APP|u CONFIG | |“测试”;
console.info(“[info]网页中的NodeJS环境:”+nodeEnvironment);
console.info(“[info]在网页包中使用的配置:”+appConfig);
module.exports={
目标:“网络”,
上下文:path.resolve(uu dirname,'ng1App'),
决心:{
扩展:['.ts'、'.js'、'.tsx'、'.json']
},
模块:{
规则:[
{
测试:/\.pug$/,,
使用:[{
loader:'ng cache loader?module=views&prefix=app:*',//ng cache loader不理解新语法
}, {
加载器:“帕格html加载器”,
选项:{
漂亮:错,
出口:假,
doctype:'html'
}
}]
},//结束帕格
{
测试:/\.ts$/,,
排除:[/node_modules/],
使用:[
{
加载器:“ng注释加载器”,
选项:{
真的吗
}
},
{
加载器:“ts加载器”,
选项:{
transpileOnly:正确
}
},
{
加载器:“tslint加载器”,
选项:{
错误:错误,
失败提示:false
}
}]
},//结束类型脚本
{
测试:/\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?(\?[0-9]+)?$/,
用法:[“文件加载器”]
},
{
测试:/\(ttf | eot | svg)(\?v=[0-9]\[0-9]\[0-9])?(\?[0-9]+)?$/,
用法:[“文件加载器”]
},
{
测试:/\.jpe?g$\.ico$\.gif$\.png$\.wav$\.mp3$/,
加载器:“文件加载器?名称=[name].[ext]'//请添加完整的网页包配置。请添加完整的网页包配置。