Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

aaronfrost commented Jul 30, 2020

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