百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

inline-source

> 编程语言
开源

用于在 HTML 中嵌入标记的 js、css 和 img 资源的工具

199 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

用于在 HTML 中嵌入标记的 js、css 和 img 资源的工具

inline-source

Inline and compress tags that contain the inline attribute. Supports `


```javascript
import { inlineSource } from 'inline-source';
import fs from 'node:fs';
import path from 'node:path';

const htmlpath = path.resolve('project/src/html/index.html');

inlineSource(htmlpath, {
  compress: true,
  rootpath: path.resolve('www'),
  // Skip all css types and png formats
  ignore: ['css', 'png'],
})
  .then((html) => {
    // Do something with html
  })
  .catch((err) => {
    // Handle error
  });

...or preferably using async/await:

javascript
import { inlineSource } from 'inline-source';
import fs from 'node:fs';
import path from 'node:path';

const htmlpath = path.resolve('project/src/html/index.html');

try {
  const html = await inlineSource(htmlpath, {
    compress: true,
    rootpath: path.resolve('www'),
    // Skip all css types and png formats
    ignore: ['css', 'png'],
  });
  // Do something with html
} catch (err) {
  // Handle error
}

…

bash
js
export function handler(source, context) {
  if (source.fileContent && !source.content && source.type == 'js') {
    source.content = "Hey! I'm overriding the file's content!";
  }
}

In general, default file content processing will be skipped if source.content is already set, and default wrapping of processed content will be skipped if source.replace is already set.

Custom Pre Handlers

Custom pre handlers are the same as custom handlers only they run before loading the file. All handlers have the following signature: (source: Source, context: Context) => Promise | void

With custom Pre handlers you can make changes to the file name

javascript
export function prehandler(source, context) {
  const { version } = getVersionFromSomewhere();
  source.filepath = source.filepath.replace('.js', `_${version}.js`);
}

Props

Source props are a subset of attributes that are namespaced with the current global attribute ('inline' by default), and allow declaratively passing data or settings to handlers:

xml
javascript
export function handler(source, context) {
  if (source.fileContent && !source.content && source.type == 'js') {
    // The `inline-compress` attribute automatically overrides the global flag
    if (!source.compress) {
      // do something
    }
    if (source.props.foo == 'foo') {
      // foo content
    }
  }
}

Issues· 12 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言