diff --git a/index.js b/index.js index ab1cdc2..bae5824 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ function viteTwigPlugin(options) { transformIndexHtml: { enforce: 'pre', async transform(content) { - const { template, data } = parseHTML(content) + const { template, data } = parseHTML(content, settings.views) return template ? await renderTemplate(template, { ...globals, ...data }, settings) : content diff --git a/package.json b/package.json index 8d7e9c0..2d2529c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-twig", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "keywords": [ "vite-plugin", diff --git a/tasks.js b/tasks.js index 6df7057..807a090 100644 --- a/tasks.js +++ b/tasks.js @@ -29,13 +29,14 @@ function configureTwig({ functions = {}, filters = {} } = {}) { /** * It handles the original html content parsing in order to retrieve the template details * @param {string} content + * @param {string} basePath * @returns {object} */ -function parseHTML(content) { +function parseHTML(content, basePath = '') { try { const [_, specs] = content.match(/]*>([\s\S]+)<\/script>/) || [] const { template, data } = JSON.parse(specs || content) - return { template: path.resolve(process.cwd(), template), data } + return { template: path.join(process.cwd(), basePath, template), data } } catch (err) { console.warn(err) return {}