Skip to content

Instantly share code, notes, and snippets.

@p3x-robot
Last active February 25, 2019 11:02
Show Gist options
  • Save p3x-robot/e12ed76acb7033638b4179149546bb73 to your computer and use it in GitHub Desktop.
Save p3x-robot/e12ed76acb7033638b4179149546bb73 to your computer and use it in GitHub Desktop.
⛮ How to disable the remove Angular decorators @ngtools/webpack mess
const fs = require('fs');
const cwd = process.cwd();
const hackPath = `${cwd}/node_modules/@ngtools/webpack/src`
const hackFileName = `${hackPath}/angular_compiler_plugin.js`
const hackFileNameHacked = `${hackFileName}.hacked`
const log = '@ngtool/webpack angular decorators remove'
const hack = () => {
if (!fs.existsSync(hackFileNameHacked)) {
const problemCode = fs.readFileSync(hackFileName).toString('utf-8').split('\n');
for(let index in problemCode) {
let line = problemCode[index];
if (line.includes('removeDecorators')) {
if (!line.startsWith('//')) {
line = '//' + line;
problemCode[index] = line;
}
break;
}
}
const generatedHack = problemCode.join('\n');
fs.writeFileSync(hackFileName, generatedHack)
fs.writeFile(hackFileNameHacked, log, function(err) {
if(err) {
throw err;
}
console.log(`${log} hack is cached`)
});
console.log(`${log} is commented now`)
} else {
console.log(`${log} hack is cached`)
}
}
module.exports.hack = hack;
if (options.AOT ) {
require('./hack-remove-decorators').hack();
// it is important so that you hack it before you load the AngularCompilerPlugin
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
plugins.push(
new AngularCompilerPlugin({
tsConfigPath: root('./tsconfig.aot.json'),
entryModule: root('/module#Module'),
// skipCodeGeneration: true,
})
)
}
@p3x-robot
Copy link
Author

@p3x-robot
Copy link
Author

p3x-robot commented Oct 26, 2018

the actual error was in the grunt-webpack package, i created a grunt task as above and now it works webpack-contrib/grunt-webpack#168 (comment)

@PascalGit1
Copy link

Where do i edit/put these fields? In @ngtools/webpack/src?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment