I want to strip a ts code before angular compiler. Here is how it looks like before the compilation:
...
/* prod:start */
const title: string = "Production title!"
/* prod:end */
/* dev:start */
const title: string = "Dev title!"
/* dev:end */
To strip ts code i'm using webpack-remove-block-loader loader in custom-webpack configurations
module.exports = {
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
enforce: 'pre',
use: [
{
loader: 'webpack-remove-block-loader',
options: {
active: true,
blocks: excludedClients.blocks,
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
...
To make custom-webpack works i'm using @angular-builders/custom-webpack with this config in angular.json:
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./custom-webpack.config.js",
"mergeRules": {
"module": {
"rules": "prepend"
}
},
...
The problem is that it doesn't work. If i remove enforce: 'pre' flag from custom-webpack config for loader that strip ts code - it'll remove blocks of code from already compiled ts files, that's wrong, otherwise with enforce: 'pre' it should works before angular compiler, but it doesn't, code is still have comments for both types of build(prod/dev).
And yes, i know that it's possible to use options from environment.ts
files but it's not flexible enough.
Thanks!