【问题标题】:how can I use babel stand alone in ie11如何在 ie11 中单独使用 babel
【发布时间】:2021-07-30 18:25:38
【问题描述】:

我正在尝试单独使用 babel。 在 ie11 之前一切正常。在 ie11 中我得到一个空白页,找不到任何错误。

在下面运行 sn-p。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    
    <div id="templateContainer"></div>

    <script id="template" type="text/x-handlbars-template">
        <div class="container">
            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                {{#each panels}}
                <!-- Academic Group -->
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="{{id}}">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapse{{@index}}"><span class="glyphicon glyphicon-plus"></span>{{title}}</a>
                        </h4>
                    </div>
                    <div id="collapse{{@index}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="{{id}}">
                        <ul class="list-group">
                            {{#each this.children}}
                            <li class="list-group-item">
                                <span class="glyphicon glyphicon-minus text-primary"></span>
                                <a href="/sites/csl/SitePages/StaffHelpPages/{{this.aspx}}.aspx" title="{{title}}">{{title}}</a>
                            </li>
                            {{/each}}
                        </ul>
                    </div>
                </div>
                {{/each}}
            </div>
        </div>
    </script>
    <script type="text/babel" data-presets="es2015, es2016, es2017, stage-3">
        const data = {
            panels: [
                {
                    title: 'Academic', id: 'headingOne',
                    children: [
                        { title: 'AY20 Academic Calendar', aspx: 'AY_Calendar' },
                        { title: 'Compass', aspx: 'Compass' },
                        { title: 'Gift Funds', aspx: 'Gift_Funds' },
                        { title: 'Manuscript Clearance for Public Release', aspx: 'Manuscript_Clearance_for_Public_Release' },
                        { title: 'Mementos', aspx: 'Mementos' },
                    ]
                },
                {
                    title: 'Admin', id: 'headingTwo',
                    children: [
                        { title: 'Alternate_Work_Schedule', aspx: 'Alternate Work Schedule' },
                        { title: 'Civilian Personnel System Access Requests', aspx: 'Civilian_Personnel_System_Access_Requests' },
                        { title: 'Comp Time / Overtime Form', aspx: 'Comp_Time_Form' },
                        { title: 'CSL Leadership Contact Numbers', aspx: 'CSL_Leadership_Contact_Numbers' },
                        { title: 'Federal and Training Holidays', aspx: 'Federal_and_Training_Holidays' },
                        { title: 'Gears', aspx: 'Gears' },
                        { title: 'HHD Leave and Passes', aspx: 'HHD_Leave_and_Passes' },
                        { title: 'Military Leave Requests', aspx: 'Military Leave Requests' },
                        { title: 'NCOER', aspx: 'NCOER' },
                        { title: 'Pentagon', aspx: 'Pentagon' },
                    ]
                },
            ]
        }


        const source = $("#template").html();
        const template = Handlebars.compile(source);
        const output = template(data);
        $("#templateContainer").append(output);
    </script>

【问题讨论】:

  • @Daniel White。运行 sn-p 这是一个最小的可重现示例。
  • standalone 用于随机 REPL 和演示,不适用于任何生产用例。如果您需要编译应用程序以在旧环境中运行,则应设置适当的构建过程以在部署代码之前对其进行编译。
  • 它是一个旧的共享点站点,允许您将 html / javascript 添加为 Web 部件。我们仍然支持ie11,我想使用es6。因此是独立的。

标签: javascript babeljs internet-explorer-11


【解决方案1】:

以防其他人在 babel 独立修复 ie11 之前添加 core-js 遇到此问题。

  <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.16.0/minified.js" type="text/javascript"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

【讨论】:

  • 感谢您发布此问题的解决方案。您可以将您的答案标记为已接受的答案。它可以在未来帮助其他社区成员解决类似的问题。感谢您的理解。
猜你喜欢
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
相关资源
最近更新 更多