Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompile/compile with nunjucks files #310

Open
rrdesignweb opened this issue Dec 15, 2022 · 0 comments
Open

Precompile/compile with nunjucks files #310

rrdesignweb opened this issue Dec 15, 2022 · 0 comments

Comments

@rrdesignweb
Copy link

rrdesignweb commented Dec 15, 2022

Hi there this is a long shot but, hope someone can help,

I am using gulp-inline-source-html (https://github.com/exuanbo/gulp-inline-source-html) & gulp-nunjucks-render (https://github.com/carlitoplatanito/gulp-nunjucks-render) plus browserSync to show the updated UI

I understand the plugin I am using is not the plugin in question but has inline-source under the hood

The plugin does something, but the problem is i don't think it properly writes the file, only when I do a hard refresh the UI is updated.

gulpfile.js

pipe(nunjucksRender({
    path: njkPaths,
    ext: "",
    data: ENV_VARS,
    envOptions: {
         trimBlocks: true,
         lstripBlocks: true
    }
}))
 .pipe(inlineSource({
    compress: false,
    saveRemote: true,
    handlers: [require("./nunjucksHandler.js")] ??
 }))

I was trying the precompile approach #70 (comment) but got nowhere.

nunjucksHandler.js

const Nunjucks = require('nunjucks');

module.exports = function nunjucks(source, context) {
    return new Promise((resolve, reject) => {
        if (
            source.fileContent &&
            !source.content &&
            source.type == "text/css"
        ) {
            let content;
            try {
                content = Nunjucks.precompile(source.fileContent);
            } catch (err) {
                return reject(err);
            }
            // Need to expose templates for later use somehow...
            source.content = content
        }

        resolve();
    });
};

.nunjucks

...
<link inline href="{{ENV_PARTIALS_BASE_PATH}}/common/terms-and-conditions/index.css" rel="stylesheet"/>
<section>html</section>
{% somenunjucks syntax etc %}
...

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant