Skip to content

Commit

Permalink
fixed dist file output
Browse files Browse the repository at this point in the history
  • Loading branch information
donnikitos committed Sep 5, 2023
1 parent bf1e164 commit 189df35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-php",
"version": "1.0.2",
"version": "1.0.4",
"description": "Precompile PHP-files with the speed of Vite",
"keywords": [
"vite",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ function usePHP(cfg: UsePHPConfig = {}): Plugin[] {
const distDir = config?.build.outDir;

entries.forEach((file) => {
const code = unescapePHP(`${tempDir}/${file}.html`);
const code = unescapePHP(
`${distDir}/${tempDir}/${file}.html`,
`${tempDir}/${file}.html.json`,
);

writeFile(`${distDir}/${file}`, code);
});
Expand Down
8 changes: 4 additions & 4 deletions src/utils/escapePHP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export function escapePHP(inputFile: string, outputFile: string) {
writeFile(outputFile, out);
}

export function unescapePHP(file: string) {
export function unescapePHP(file: string, tokensFile?: string) {
const input = readFileSync(file).toString();
let out = input;

const tokensFile = file + '.json';
if (existsSync(tokensFile)) {
const codeTokens = JSON.parse(readFileSync(tokensFile).toString());
const tknsFile = tokensFile || file + '.json';
if (existsSync(tknsFile)) {
const codeTokens = JSON.parse(readFileSync(tknsFile).toString());

Object.entries(codeTokens).forEach(([token, code]) => {
out = out.replace(token, (match) => {
Expand Down

0 comments on commit 189df35

Please sign in to comment.