相关疑难解决方法(0)

ES6模块导入是否执行导入文件中的代码?

js文件中的代码是否在导入期间运行?如果是,那么一次还是每次?例如

// a.js
console.log("A");
const a = "a"; 
export default a;

// b.js
import a from "./a"; // => console logs?

// c.js
import a from "./a"; // => console logs again?
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

45
推荐指数
2
解决办法
1万
查看次数

聚合物“ <custom-style>”:哪一行代码停止将相同的自定义样式模板模块的多个导入追加到DOM?

我项目的上游Web组件主题实现为<custom-style>元素链接

我想将我的文档级别替代实现为JS模块(例如,避免将其硬编码到应用程序index.html或等效文件中),从表面上看这很简单:

import '@vaadin/vaadin-lumo-styles/color.js';

const $template = document.createElement('template');

$template.innerHTML = `
<custom-style>
  <style>
  html,
  :host {
    --lumo-primary-color: red;
  }
  </style>
</custom-style>`;

document.head.appendChild($template.content);
Run Code Online (Sandbox Code Playgroud)

文档中使用的某些Web组件也会通过导入原始主题import '@vaadin/vaadin-lumo-styles/color.js'

我希望我的替代项总是最后级联(没有!importanthack)。

以后是否有多个import '@vaadin/vaadin-lumo-styles/color.js';调用有可能还原我的CSS自定义属性覆盖级联?

认为:

  • 原版的: --lumo-primary-color: hsl(214, 90%, 52%);
  • 我:导入原始文件,覆盖 --lumo-primary-color: red;
  • 以后:以后可以将原始的“重置”级联导入到--lumo-primary-color: hsl(214, 90%, 52%);)吗?

ES6在多个位置导入文件,为什么文件一次加载?似乎没有暗示,但是我正在努力寻找任何明确说明某事的文档<custom-style>

也许https://github.com/Polymer/polymer/blob/v3.2.0/lib/elements/custom-style.js#L80是关键?

毛刺

https://glitch.com/edit/#!/roan-pizza?path=src/index.js似乎确认重复的导入似乎不会引起问题,但是为什么呢?是纯粹由于ES6模块负载缓存引起的,还是其他原因?

<custom-style>浏览器检查器中的EDIT拖放元素肯定会对级联产生影响(颜色根据标记顺序更改),因此至少可以确定加载顺序很重要。

javascript vaadin web-component polymer es6-modules

5
推荐指数
1
解决办法
192
查看次数