Last active
October 1, 2017 20:38
-
-
Save MarkPieszak/2e26dad20640d152fde183f1edb4530d to your computer and use it in GitHub Desktop.
Using Pug templates with the Angular-CLI script insert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const commonCliConfig = 'node_modules/@angular/cli/models/webpack-configs/common.js'; | |
const pug_rule = `\n{ test: /.(pug|jade)$/, loader: "apply-loader!pug-loader?self" },`; | |
fs.readFile(commonCliConfig, (err, data) => { | |
if (err) { throw err; } | |
const configText = data.toString(); | |
// make sure we don't add the rule if it already exists | |
if (configText.indexOf(pug_rule) > -1) { return; } | |
// We made it this far, let's insert that pug webpack rule | |
const position = configText.indexOf('rules: [') + 8; | |
const output = [configText.slice(0, position), pug_rule, configText.slice(position)].join(''); | |
const file = fs.openSync(commonCliConfig, 'r+'); | |
fs.writeFile(file, output); // ta-da | |
fs.close(file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment