Angular 6 アプリケーションをホストする .net Core 2.1 MVC アプリケーションがあります。私はそれをバンドルするためにwebpack 4を使用しています。最適化の利点のためにコードを醜くし、展開時にコードを可能な限り保護したいと考えています。プロパティ名を変更しようとすると、Angular アプリが動作を停止し、「Uncaught ReferenceError: vendor_8b8ec7e9d2171cd0b5b6」が定義されていません」というエラーが表示されます。mangle プロパティで「プロパティ」パラメーターを true から false に設定すると、すべて機能します。しかし、プロパティと関数の名前は醜いコードに含まれています。
助けてください。
私のwebpack.config.js:
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('bundle.min.css');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = (env) =>
{
// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = './wwwroot/dist';
// Configuration in common to both client-side and server-side bundles
const isDevBuild = !(env && env.prod);
const sharedConfig = {
mode: 'production',
stats: { modules: false },
context: __dirname,
resolve: { extensions: ['.js', '.ts'] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize'] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [
new CheckerPlugin(),
new CopyWebpackPlugin([{ from: __dirname + '/node_modules/font-awesome/fonts', to: __dirname + '/wwwroot/dist/fonts' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/node_modules/font-awesome/css/font-awesome.css', to: __dirname + '/wwwroot/dist/fonts' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/node_modules/@progress/kendo-theme-default/dist/all.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/core.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro-colors.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro-icons.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro-responsive.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro-rtl.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/assets/css/metro-schemes.min.css', to: __dirname + '/wwwroot/dist/' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/images', to: __dirname + '/wwwroot/dist/images' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/accessoryimages', to: __dirname + '/wwwroot/dist/accessoryimages' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/layoutimages', to: __dirname + '/wwwroot/dist/layoutimages' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/documents', to: __dirname + '/wwwroot/dist/documents' }], { copyUnmodified: true }),
new CopyWebpackPlugin([{ from: __dirname + '/ClientApp/Fonts', to: __dirname + '/wwwroot/dist/fonts' }], { copyUnmodified: true })
]
};
const clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot.browser.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
exclude: ['./**/*.server.ts']
})
]),
optimization: {
minimizer: [].concat(isDevBuild ? [] : [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: true,
ecma: 6,
mangle: {
toplevel: true, properties: false
},
toplevel: true,
keep_classnames: false,
keep_fnames: false
},
sourceMap: false
})
])
}
});
// Configuration for server-side (prerendering) bundle suitable for running in Node
const serverBundleConfig = merge(sharedConfig, {
resolve: { mainFields: ['main'] },
entry: { 'main-server': './ClientApp/boot.server.ts' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
].concat(isDevBuild ? [] : [
// Plugins that apply in production builds only
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
exclude: ['./**/*.browser.ts']
})
]),
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map',
optimization: {
minimizer: [].concat(isDevBuild ? [] : [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: true,
ecma: 6,
mangle: {
toplevel: true, properties: false
},
toplevel: true,
keep_classnames: false,
keep_fnames: false
},
sourceMap: false
})
])
}
});
return [clientBundleConfig, serverBundleConfig];
};