小编Gur*_*ofu的帖子

Laravel-Mix:开发和生产构建的不同输出路径(以css为例)

我们webpack.mix在制作应用程序后看到的所有内容如下:

const { mix } = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');
Run Code Online (Sandbox Code Playgroud)

我知道如何运行开发和生产构建,但不知道如何自定义它。在这个问题上,我们认为有关编译的例子sass,以css在根据构建类型不同的道路,但我想用工作es6pug建设将是相似的。

项目结构

民众

???css-prod

资源

? 资产

???蠢货

???css-dev

我想要:

  • 开发执行:来自resources/assets/sasscompile 的文件resources/assets/css-dev,没有丑化,没有串联。
  • 生产执行:从resources/assets/sasscompile 到resources/assets/css-prod, uglify 和 concatenate 的文件。

我应该在哪里定义这些设置?

laravel-5.4 laravel-mix

3
推荐指数
1
解决办法
2944
查看次数

Node.js 和前端 Web 应用程序的单独 babel 配置是同一个项目

我不仅需要Babel用于 Web 应用程序(由 Webpack 构建),还需要用于 Nodejs 自动化实用程序,例如gulp. 一般情况下,web应用和nodejs的babel设置不能相同。问题是如何将其分开。

我还没有测试过,但我想我们可以.babelrc直接在 webpack 配置中定义 Nodejs 的设置和 Web 应用程序的设置,例如:

module.exports = {

  // ...

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader?blacklist[]=regenerator',
            options: {
              presets: [
                ['env', {'modules': false}]
              ],
              plugins: [
                'syntax-dynamic-import',
                'transform-runtime'
              ]
            }
          },
          'eslint-loader'
        ]
      }
    ]
  }
};
Run Code Online (Sandbox Code Playgroud)

问题是哪个配置 webpack 将给予更高的优先级:.babelrc或 webpack 加载器选项(需要第二个)。

javascript node.js webpack

3
推荐指数
1
解决办法
1044
查看次数

3列CSS网格布局中取半宽

我们可以通过 CSS 网格创建如下图所示的布局吗?

在此输入图像描述

css css-grid

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

<input type="number"> 不会阻止无效数字输入,但“element.value”不允许我更正它们

来自MDN 文档关于<input type="number">

它们包括用于拒绝非数字条目的内置验证。

这是否意味着“尝试提交 HTML 表单时拒绝”?我输入了“4e4--23”。HTML 没有拒绝它。

在此处输入图片说明

因此,<input type="number"> 不能阻止非数值的输入。如果我可以以编程方式更正用户的输入,我不在乎。例如,用户输入的减号不在第一个位置 -理论上使用 JavaScript我可以删除它。

然而,这是不明显的 JavaScript 行为:当输入元素具有“数字”属性并且value是无效数字时,Element.value返回一个空字符串。这是非常棘手的编程验证:因为我们有空字符串值,验证器将返回“输入不能为空。请输入值。” 输入不为空时出错!

document.getElementById("target").addEventListener("input", blackbox => {
 console.log(document.getElementById("target").value);
});
Run Code Online (Sandbox Code Playgroud)
<input type="number" value="" id="target">
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到实际输入的值?(如果你知道Vue,也请添加Vue的解决方案。)

html javascript vue.js

3
推荐指数
1
解决办法
494
查看次数

如何让标签的高度与 JavaFX 中的字体大小相同?

我将上标签的字体大小设置为 24px。我不知道在哪里可以检查元素的实际高度(如果在场景构建器中可能的话),但是盒子的上部(在图像中指定)和下部有额外的空间。

  • 行间距为0
  • 父 VBox 没有顶部填充。
  • 计算所有标签大小。

在此处输入图片说明

我需要标签的高度等于字体大小。我的意思是FontSize = Gray space surrounded by blue markers height

如何达到?

我遇到过类似的问题 HTML/CSS。在那里,对于大多数情况来说,不是简单但有效的解决方案是负边距:before:after伪元素。

现在有哪些适用于 JavaFX 的解决方案?

再现

存储库

resources/static/TasksOverview.fxml通过场景生成器打开。

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="640.0" prefWidth="320.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <HBox alignment="CENTER_LEFT">
         <children>
            <CheckBox mnemonicParsing="false" />
            <VBox>
               <children>
                  <Label style="-fx-font-size: 24px;" text="Wake up">
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Label>
                  <Label style="-fx-font-size: 14px;" …
Run Code Online (Sandbox Code Playgroud)

javafx fxml scenebuilder

3
推荐指数
1
解决办法
330
查看次数

NodeJS:2021 年干预 Steam 的“through2”的实际原生替代品

来自through2文档:

\n
\n

你需要这个吗?

\n

自从 Node.js 引入了简化流构造以来,\nthrough2 的许多使用都变得多余了。考虑您是否确实需要\n使用 through2 还是只想使用\'readable-stream\' 包或\n核心\'stream\' 包(源自\'readable-stream\')。

\n
\n

如果我理解正确的话,现在(从 2021 年开始)我们可以在没有第三方库的情况下干预流。\n我没有找到如何执行与Stream 文档through2中相同的操作。

\n
// ...\n  .pipe(through2(function (file, encoding, callback) {\n    // Do something with file ...\n    callback(null, file)\n   }))\n\n// \xe2\x86\x91 Possible to reach the same effect natively (with core packages)?\n
Run Code Online (Sandbox Code Playgroud)\n

我想,2021 年一定会有一些支持 async/await 语法的方法:

\n
// ...\n  .pipe(newFeatureOfModernNodeJS(async function (file) {\n\n    await doSomethingAsyncWithFile(file);\n    // on fail - same effect as "callback(new Error(\'...\'))" of trough2\n\n    return file; // …
Run Code Online (Sandbox Code Playgroud)

node.js through2

3
推荐指数
1
解决办法
596
查看次数

C#:数组属性的getter和setter表达式

如何CoolerFanIsOn在类中编写数组属性的getter和setter表达式CoolerSystem?我展示了非阵列属性的类似的所需表达IsOnLamp类.

class CoolerFan{

    bool isOn;
    public bool IsOn {
        get => isOn;
        set {
            isOn = value;
        }
    }
}

class CoolerSystem {

    private CoolerFan[] = new CoolerFan[5];
    private bool[] coolerFanIsOn = new Boolean[5];

    // invalid code from now

    public bool[] CoolerFanIsOn {
        get => coolerFanIsOn[number];
        set {
            coolerFanIsOn[number] = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

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

在 Vue 中条件渲染后将焦点放在输入字段上

目标

单击“编辑”按钮时,将出现输入字段并自动聚焦。

<button v-if="!editingMode" @click="editingMode = !editingMode">edit</button>
<input v-else type="text" value ref="input">
Run Code Online (Sandbox Code Playgroud)
export default {
  name: "App",
  components: {
    HelloWorld
  },
  data: function() {
    return {
      editingMode: false
    };
  },
  methods: {
    onClickButton() {
      this.editingMode = true;
      this.$refs.input.focus();
    }
  }
};
Run Code Online (Sandbox Code Playgroud)

小提琴

问题

因为Vue中的重新渲染是同步的,所以当我们调用 时this.$refs.input.focus(),输入字段可能还没有渲染。我经历过两个案例:

  1. 输入尚未安装。在这种情况下,Error in v-on handler: "TypeError: Cannot read property 'focus' of undefined"就会出现。
  2. 没有这个错误,但也没有焦点。看起来输入字段已安装和准备操作之间存在间隔。

vue.js

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

解决类字段的“@typescript-eslint/no-invalid-this”问题,而不与“@typescript-eslint/no-this-alias”冲突

在下面的代码中:

\n
import { Vue, Component } from "vue-property-decorator";  \n\n\n@Component({\n  components: {}\n})\nexport default class ProductViewingAndEditingPage extends Vue {\n\n  private readonly componentsReferencesIDs: {\n    productTitleInputField: string;\n    productPriceInputControl: string;\n  } = {\n    productTitleInputField: "ProductTitle--InputField",\n    productPriceInputControl: "ProductPrice--InputComponent"\n  };\n\n  private readonly productDataFormValidator: InputsGroupValidator = new InputsGroupValidator({\n    controls: {\n      [this.componentsReferencesIDs.productTitleInputField]:\n          this.$refs[this.componentsReferencesIDs.productTitleInputField],\n      [this.componentsReferencesIDs.productPriceInputControl]:\n          this.$refs[this.componentsReferencesIDs.productPriceInputControl]\n    }\n  });\n}\n
Run Code Online (Sandbox Code Playgroud)\n

@typescript/eslint发出@typescript-eslint/no-invalid-this问题(因为它不是 ESLint no-invalid-this,该规则理解类字段。)。

\n

关于概念解决方案的思考

\n

如果我使用componentsReferencesIDs静态类字段,则无法从 vue 模板中检索值。

\n

这里不能使用箭头函数,因为这里是类字段。而且,如果我们使用 alias this,我们将面临no-this-alias规则。

\n

我知道 ESLint 并不是唯一的事实来源。但我想要这样的理由:“因为 \xe3\x80\x88argument\xe3\x80\x89,这个 ESLint 规则不涵盖这种情况。”

\n

typescript eslint typescript-class typescript-eslint

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

在窄屏幕上通过“display: none”隐藏元素是否会影响可访问性 - 如果是,如何修复?

假设根据设计,红色按钮必须仅显示在宽屏幕上。

在此输入图像描述

如果只是展示它,没有什么困难,但我会跳过装饰。

.Container {
  display: flex;
  column-gap: 12px;
}

@media screen and (max-width: 340px) {
  .Button__WideScreensOnly {
    display: none;
  }
}
Run Code Online (Sandbox Code Playgroud)
<div class="Container">
   <button class="Button">Button</button>
   <button class="Button">Button</button>
   <button class="Button Button__WideScreensOnly">Narrow screens only</button>
</div>
Run Code Online (Sandbox Code Playgroud)

据我所知,辅助功能软件不尊重 CSS,因此第三个按钮对于辅助功能软件始终可见。但是用户(例如视力较弱但如果屏幕阅读器能够读取按钮标签则能够按下按钮)无法在狭窄的屏幕上按下按钮。

辅助软件标记隐藏元素的常见解决方案是“隐藏”属性(标签的属性,而不是 CSS 属性)。但据我所知,这些属性不能依赖于媒体查询。

html css accessibility

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