StuBlackett
StuBlackett

Reputation: 3857

Webpack - Use variable to compile

I'm using Laravel & Webpack to compile CSS for 4 different themes. But each time I only want to compile the one theme.

I am storing in my Database a template_home variable. I don't mind putting this var in my .env file either..

Ideally I'd like to then use that variable to compile one of the 4 mixes.

Is this possible?

Thanks

Upvotes: 0

Views: 132

Answers (1)

Jonas
Jonas

Reputation: 42

Yes, this should be possible with the dotenv npm package.

  1. First install the package with npm: npm install dotenv --save-dev.

  2. Then add the template key to the .env-file:

...
THEME_KEY=test_01
...
  1. To access and use the variable you need to edit your webpack.mix.js-file:
const mix = require('laravel-mix');
const dotenv = require('dotenv').config();

mix.sass('resources/assets/sass/' + process.env.THEME_KEY + '.scss', 'css');

Hope this helps!

Upvotes: 1

Related Questions