小编Jus*_*elt的帖子

加载 jQuery 等外部脚本时出现问题

从今天早上开始,我就遇到了一个问题,使用 Apps 脚本部署的 web 应用程序以前运行良好。当然,没有做出任何改变来证明这个问题的合理性。

外部脚本不会从 HTML 端加载,并且控制台中会出现新错误。

为了有一个可重现的例子:

代码.gs

function doGet() {

  var template = HtmlService.createTemplateFromFile('index');

  return template.evaluate()
                .setTitle('TEST')
                .addMetaTag('viewport', 'width=device-width, initial-scale=1')
                .setSandboxMode(HtmlService.SandboxMode.IFRAME)
}
Run Code Online (Sandbox Code Playgroud)

索引.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  </head>
  <body>
        <div id="title">Hello</div>
  </body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

  <script>
    window.onload = function() {

      console.log('loaded');
      console.log($('#title').html());

    }
  </script>
</html>
Run Code Online (Sandbox Code Playgroud)

控制台中的结果:

[ERROR] This document requires 'TrustedHTML' assignment. (jquery.min.js:2)

[ERROR] Uncaught TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment. (jquery.min.js:2)

[LOG] loaded …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery google-apps-script google-workspace

17
推荐指数
2
解决办法
2443
查看次数

使用 Rollup 保留独立评论

我试图用汇总保留尾随的独立评论。我简要地浏览了使用插件扩展 rollup 或深入研究 AST,但正在寻找可能的解决方案的指导。

输入

// Some comment

const foo = {};

// Another comment <-- I want this to remain

export { foo };
Run Code Online (Sandbox Code Playgroud)

输出

(function (exports) {
    'use strict';

    // Some comment

    const foo = {};

    exports.foo = foo;

    return exports;

}({}));
Run Code Online (Sandbox Code Playgroud)

汇总配置

export default [
  {
    input: "src/index.js",
    plugins: [],
    output: {
      file: "dist/index.js",
      format: "iife",
      name: "foo"
    },
    treeshake: false
  }
];
Run Code Online (Sandbox Code Playgroud)

rollupjs

5
推荐指数
0
解决办法
737
查看次数