Skip to content

Instantly share code, notes, and snippets.

@p3x-robot
Last active February 25, 2019 11:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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,
})
)
}
@bradproctor
Copy link

bradproctor commented Aug 3, 2018

After implementing this, all of my angular components fail to inline the templates and styles. The components are trying to reference the .html and .less files at runtime, causing tons of 404 errors. Is this expected, or am I missing something?

angular v6.1.1
ngtools/webpack v6.1.2

@p3x-robot
Copy link
Author

I use the latest, I think it is the build .json you are using, that could be causing this. I use it and works, inline and with require as well. Actually, I do not use templateUrl, that's for sure.

@p3x-robot
Copy link
Author

it looks like for me since i started using the pure webpack it started working, i think the error is in grunt-webpack, that's when this error occurs.

@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