Angular tree shaking not stripping dev code, what things should I look for?

The post that you linked to specifically states that the tree-shaking occurs for 'Code gated by constants in if statements' . So you may need to alter your if statement to:

if (environment.production===true) {
  console.warn('this is a prod build');
  console.warn('this is a dev build');

to introduce the presence of a constant.

You could apply the same logic as environment.ts; create (without the dev specific code) and (with dev specific code), then use fileReplacements in your config.

The config for prod would be:

 "fileReplacements": [
        "replace": "src/main.ts",
        "with": "src/"