moyus / laravel-mix-nunjucks

Laravel Mix extension to compile Nunjucks templates
MIT License
11 stars 5 forks source link

How manageEnv works? #4

Closed levipadre closed 4 years ago

levipadre commented 4 years ago

I need to pass 'development' or 'production' to environment, like mix.inProduction() ? 'production' : 'development'. But don't know how that works with manageEnv.

I have something like this (the mentioned part is wrong of course):

mix.njk(paths.src.templates, (mix.inProduction() ? paths.dist.base : paths.temp.base), {
        ext: '.html',
        data: require('./data.json'),
        envOptions: {
            lstripBlocks: true,
            autoescape: true,
            trimBlocks: true
        },
        manageEnv: {
            'environment': mix.inProduction() ? 'production' : 'development'
        }
    });
levipadre commented 4 years ago

If anybody needs it, I figured it out at the end:

data: {
    ...(require('./data.json')),
    environment: mix.inProduction() ? 'production' : 'development'
},