-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luki
committed
Aug 21, 2024
1 parent
40beb51
commit 336061a
Showing
28 changed files
with
451 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
--- | ||
title: TheGraph区块链索引 | ||
date: 2023-10-30 14:31:35 | ||
permalink: /pages/1495b0/ | ||
categories: | ||
- 学习笔记 | ||
- web3 | ||
tags: | ||
- | ||
author: | ||
name: 夏天夏 | ||
link: https://github.com/qq919006380 | ||
--- | ||
[The Graph入门教程:如何索引合约事件](https://learnblockchain.cn/article/2466) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,83 @@ | ||
require加载资源策略 | ||
1,只能加载js,json,node.exe,.node文件 | ||
2,如果是其他后缀入md,txt则当js引入,如果文件内不是js内容则报错 | ||
--- | ||
title: cli笔记 | ||
date: 2021-06-24 15:07:13 | ||
permalink: /pages/14a471/ | ||
sidebar: auto | ||
categories: | ||
- 笔记 | ||
tags: | ||
- | ||
author: | ||
name: 夏天夏 | ||
link: https://github.com/qq919006380 | ||
--- | ||
## Node.js 中的资源加载策略与模块导入 | ||
|
||
node使用import | ||
1,使用webpack打包编译 | ||
2,node14以上版本原生支持,不过js结尾改成mjs入xxx.mjs | ||
在 Node.js 开发中,处理资源文件和模块导入的策略非常重要,尤其是在使用不同的文件后缀和加载机制时。本文将探讨在 Node.js 环境中如何加载特定类型的资源文件,并介绍使用 require 和 import 的方法及其对应的策略。 | ||
|
||
## 资源加载策略 | ||
|
||
在 Node.js 中,使用 require 加载资源时,有一些文件类型是默认支持的,而其他类型的文件可能需要特定的处理策略: | ||
|
||
## 支持的文件类型 | ||
|
||
- .js:JavaScript 文件。 | ||
- .json:JSON 文件。 | ||
- .node:Node.js 的原生扩展模块文件(通常是 C++ 编写的二进制文件)。 | ||
|
||
## 处理其他文件类型 | ||
|
||
对于 .md 和 .txt 等其他后缀文件,默认情况下 require 不会直接加载这些文件。如果需要加载这些文件作为 JavaScript 文件,你需要进行特殊处理。 | ||
|
||
策略:当尝试 require 这些文件时,可以将其内容作为 JavaScript 模块进行处理。如果文件内容不是有效的 JavaScript,则需要抛出错误。 | ||
|
||
```javascript | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
function loadFile(filePath) { | ||
const ext = path.extname(filePath); | ||
|
||
if ([".js", ".json", ".node"].includes(ext)) { | ||
return require(filePath); | ||
} else if ([".md", ".txt"].includes(ext)) { | ||
const content = fs.readFileSync(filePath, "utf-8"); | ||
try { | ||
// 尝试将内容作为 JavaScript 执行 | ||
return eval(content); | ||
} catch (e) { | ||
throw new Error(`Error evaluating content of ${filePath}: ${e.message}`); | ||
} | ||
} else { | ||
throw new Error(`Unsupported file type: ${ext}`); | ||
} | ||
} | ||
``` | ||
|
||
## Node.js 中的模块导入 | ||
|
||
在 Node.js 中,使用 import 语法可以实现 ES6 模块导入,这为开发者提供了更现代化的模块管理方式。根据 Node.js 的版本和配置,import 的支持情况有所不同: | ||
|
||
## Webpack 打包编译 | ||
|
||
在使用 Webpack 时,你可以通过配置将 ES6 模块(.js 文件)打包成兼容的格式。Webpack 支持将 import 语法转换为 CommonJS 格式,这使得在 Node.js 环境中使用 import 成为可能。 | ||
|
||
## Node.js 14 及以上版本原生支持 | ||
|
||
从 Node.js 14 开始,原生支持 ES6 模块。你可以直接使用 import 语法,但文件后缀名需要改为 .mjs,以明确标识这是一个 ES6 模块。如果你希望使用 .js 文件作为模块,你需要在项目的 package.json 文件中添加 "type": "module" 字段,这样 Node.js 会将 .js 文件视作 ES6 模块。 | ||
|
||
```javascript | ||
// 使用 import 语法导入模块 | ||
import myModule from "./myModule.mjs"; | ||
``` | ||
|
||
```json | ||
// package.json 中的配置 | ||
{ | ||
"type": "module" | ||
} | ||
``` | ||
|
||
## 总结 | ||
|
||
在 Node.js 中处理不同文件类型和模块导入时,需要根据使用的文件类型和 Node.js 版本选择合适的策略。使用 require 加载特定文件类型时,需要针对不常见的文件类型编写额外的处理逻辑。而在使用 ES6 模块时,确保你的 Node.js 环境和文件配置支持 import 语法,以便充分利用现代模块化的优势。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
--- | ||
title: harbor | ||
date: 2023-12-14 18:55:08 | ||
permalink: /pages/18402f/ | ||
sidebar: auto | ||
categories: | ||
- 笔记 | ||
tags: | ||
- | ||
author: | ||
name: 夏天夏 | ||
link: https://github.com/qq919006380 | ||
--- | ||
https://goharbor.io/docs/2.0.0/install-config/configure-https/ | ||
https://goharbor.io/docs/2.0.0/install-config/troubleshoot-installation/#https |
Oops, something went wrong.