Skip to content

Commit

Permalink
fix: add func entry
Browse files Browse the repository at this point in the history
  • Loading branch information
callqh committed May 7, 2024
1 parent da6e938 commit 50cb1bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jstors/farm-plugin-html-template",
"description": "This plugin is used to dynamically replace variables injected into HTML.",
"version": "0.0.2",
"version": "0.0.3",
"main": "scripts/index.js",
"types": "scripts/index.d.ts",
"type": "module",
Expand All @@ -28,6 +28,7 @@
"require": "./scripts/index.js",
"types": "./scripts/index.d.ts"
},
"./func":"./scripts/func.js",
"./package.json": "./package.json"
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions scripts/func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import binPath from "./index.js";

export default (options)=> [binPath, options]
18 changes: 17 additions & 1 deletion scripts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
const binPath: string;
export interface IOptions {
/**
* The path to the HTML file that will be used as a template.
* eg:
* path.resolve(__dirname, 'index.html')
*/
template: string;
/**
* An object containing the variables that will be injected into the HTML file.
* eg:
* data {
* title: 'My App',
* }
*/
data: Record<string,string>
}
const binPath: (options?:IOptions)=>[string, typeof options];
export default binPath;
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ impl Plugin for FarmPluginHtmlTemplate {
fn transform(
&self,
param: &farmfe_core::plugin::PluginTransformHookParam,
context: &std::sync::Arc<farmfe_core::context::CompilationContext>,
_context: &std::sync::Arc<farmfe_core::context::CompilationContext>,
) -> farmfe_core::error::Result<Option<farmfe_core::plugin::PluginTransformHookResult>> {
// only handle html file
if ModuleType::Html == param.module_type && self.options.template == param.resolved_path {
println!("{:?}", param.resolved_path);

let content = param.content.clone();
let mut result = String::new();
for capture in self.re.captures_iter(&content) {
Expand Down

0 comments on commit 50cb1bb

Please sign in to comment.