Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Created July 30, 2020 00:26
Show Gist options
  • Select an option

  • Save aaronfrost/aa81814e778fdca7d4d18e01db643f85 to your computer and use it in GitHub Desktop.

Select an option

Save aaronfrost/aa81814e778fdca7d4d18e01db643f85 to your computer and use it in GitHub Desktop.

Revisions

  1. aaronfrost created this gist Jul 30, 2020.
    51 changes: 51 additions & 0 deletions angularjs-npxbuildplus-plugins.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    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;