Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Created July 30, 2020 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronfrost/aa81814e778fdca7d4d18e01db643f85 to your computer and use it in GitHub Desktop.
Save aaronfrost/aa81814e778fdca7d4d18e01db643f85 to your computer and use it in GitHub Desktop.
const rules = config.module.rules;
// File the rules from the build that builds all the TS files. The MainRule
const mainRule = rules.find((r) => {
// If not in prod mode, this IF will find the mainRule
if (r.loader) {
return (
r && r.loader && r.loader.endsWith(angularLoaderFilename)
);
// If in prod mode, this ELSE will find the mainRule
} else if (r && r.use) {
const loader = r.use[r.use.length - 1];
return (
typeof loader == "string" &&
loader.endsWith(angularLoaderFilename)
);
}
});
// Grab MainRule's index
const mainRuleIndex = rules.indexOf(mainRule);
const newRules = [
{
test: /\.html$/,
use: {
loader: "html-loader",
options: {
minimize: true,
collapseWhitespace: true,
collapseBooleanAttributes: false,
collapseInlineTagWhitespace: false,
conservativeCollapse: false,
},
},
},
/*{
test: mainRule.test,
exclude: /node_modules/,
use: [{ loader: "angular2-template-loader" }],
},*/
];
// Add newRules back into rules[]
for (let i = newRules.length - 1; i >= 0; i--) {
const newRule = newRules[i];
// Inserts and item into an existing array, at a certain index, without removing anything
rules.splice(mainRuleIndex, 0, newRule);
}
return config;
@aaronfrost
Copy link
Author

const path = require("path");

const angularLoaderFilename = `@ngtools${path.sep}webpack${path.sep}src${path.sep}index.js`;

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