Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds handlebar plugin to webpack build #1614

Closed
wants to merge 1 commit into from
Closed

Adds handlebar plugin to webpack build #1614

wants to merge 1 commit into from

Conversation

onedotover
Copy link

This pull request is in reference to #1544. If we bring back the ability to access environment variables, we have two main benefits.

Easier Upgrade Path
Users upgrading to the webpack version will have less difficulty if they are already taking advantage of the handlebar template logic.

Environment Specific index.html
Users can take advantage of multiple environments. I believe these are examples of typical needs for environment specific logic.

<base href={{environment.baseURL}} />

...

{{#if environment.production}}
  <script type="text/javascript">
    // Google Analytics
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-########-#', 'auto');
  </script>
{{/if}}

...

  <script type="text/javascript">
    // Load Facebook SDK for JS
    window.fbAsyncInit = function () {
      FB.init({
        appId: "{{environment.facebookAppId}}", // Test app vs Production app
        cookie: true,
        xfbml: false,
        version: "v2.7"
      });
    };
    (function (d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {
        return;
      }
      js = d.createElement(s);
      js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, "script", "facebook-jssdk"));
  </script>

Webpack Dev Server Base URL
Webpack Dev Server has an issue with baseURL: webpack/webpack-dev-server#288 By making this environment specific, users who need a nested directory structure for their SPA can use a baseURL of / for local testing using webpack dev server, but have a different value for production.

Build System Independent
There is actually a way to use variables from the HTML Plugin currently used in the form <%= htmlWebpackPlugin.options.title %>. However, this makes the templates build system specific. If you wanted to change away from Webpack later, these would not longer apply. By using handlebars, you can move between build systems.

This can also help address the following issues:
#1509
#1460
#1064

@filipesilva
Copy link
Contributor

As mentioned in #1544 (comment), this functionality was never intended and we have removed it. As such we are not looking for PRs to add it back.

@onedotover
Copy link
Author

Ah bummer. Ok well thanks for looking at this. I appreciate what you guys have done with Angular CLI! It's great!

@niklas-dahl
Copy link
Contributor

Since this is closed, is there a diffrent way to archive this?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants