I have an Angular application that I regularly update and build with the latest Webpack bundler.
Some days ago I upgraded the project to Angular 9 and encountered some issues that I couldn't resolve.
plugins: [
new ngw.AngularCompilerPlugin({
tsConfigPath: path.resolve(rootPath, 'tsconfig.aot.json'),
entryModule: path.resolve(rootPath, 'src', 'app', 'app.module#AppModule')
})
]
Below you can find my configuration files, but the whole project is available on GitHub: https://github.com/aszidien/angular-webpack-build
package.json
...
"scripts": {
"build:dev": "cross-env NODE_ENV=development webpack --mode development",
"build:prod": "cross-env NODE_ENV=production webpack --mode production",
"test": "jest"
}
...
tsconfig.aot.json
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"skipMetadataEmit": true
}
}
webpack.config.common.js
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.config.common');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
publicPath: '/',
filename: 'bundle.js',
chunkFilename: '[id].chunk.js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader', options: {
transpileOnly: true
}
},
{ loader: 'angular2-template-loader' },
{ loader: 'angular-router-loader' }
]
}
]
},
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});
webpack.config.prod.js
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.config.common');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
publicPath: '/',
filename: 'bundle.js',
chunkFilename: '[id].chunk.js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader', options: {
transpileOnly: true
}
},
{ loader: 'angular2-template-loader' },
{ loader: 'angular-router-loader' }
]
}
]
},
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With