vite-plugin-dtemplate
v1.0.7
Published
Vite Plugin DTemplate
Downloads
48
Maintainers
Readme
Install
yarn add vite-plugin-dtemplate
Usage
In vite.config.ts
:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { dTemplatePlugin } from "vite-plugin-dtemplate";
export default defineConfig({
plugins: [
react(),
dTemplatePlugin(),
],
});
Templates
Template files follow a specific extension pattern (.d.template), for example:
.env
VITE_APPLICATION_NAME="VITE"
example.d.template
Hello world by <<#VITE_APPLICATION_NAME>>
{{endLine}}
index.tsx
import React from "react";
import example from "./example.d.template";
export const App: React.FC = () => {
return (
<div>
{example}
{/* RESULT:
Hello world by VITE
{{endLine}}
*/}
</div>
);
};
OR
import React from "react";
import example from "./example.d.template";
import { fillTemplate } from "vite-plugin-dtemplate/utils";
export const App: React.FC = () => {
return (
<div>
{fillTemplate({
template: example,
params: {
endLine: "end line..."
}
})}
{/* RESULT:
Hello world by VITE
end line...
*/}
</div>
);
};
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.