Created
July 30, 2020 00:26
-
-
Save aaronfrost/aa81814e778fdca7d4d18e01db643f85 to your computer and use it in GitHub Desktop.
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 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; |
Author
aaronfrost
commented
Jul 30, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment