Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit b005d4f

Browse files
Refactor how env vars are consumed in builder
1 parent 37d8841 commit b005d4f

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

build/app.config.js

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const merge = require('webpack-merge')
33

4+
const env = require('./utils/env')
45
const config = require('../config/app')
56

67
module.exports = merge({
@@ -34,13 +35,29 @@ module.exports = merge({
3435
* @type {Object}
3536
*/
3637
outputs: {
37-
css: { filename: 'css/[name].css' },
38-
font: { filename: 'fonts/[name].[ext]' },
39-
image: { filename: 'images/[path][name].[ext]' },
40-
javascript: { filename: 'js/[name].js' },
38+
css: {
39+
filename: env('FILENAME_CSS', 'css/[name].css')
40+
},
41+
42+
font: {
43+
filename: env('FILENAME_FONT', 'fonts/[name].[ext]')
44+
},
45+
46+
image: {
47+
filename: env('FILENAME_IMAGE', 'images/[path][name].[ext]')
48+
},
49+
50+
javascript: {
51+
filename: env('FILENAME_JAVASCRIPT', 'js/[name].js')
52+
},
53+
4154
external: {
42-
image: { filename: 'images/[name].[ext]' },
43-
font: { filename: 'fonts/[name].[ext]' }
55+
image: {
56+
filename: env('FILENAME_EXTERNAL_IMAGE', 'images/[name].[ext]')
57+
},
58+
font: {
59+
filename: env('FILENAME_EXTERNAL_FONT', 'fonts/[name].[ext]')
60+
}
4461
}
4562
},
4663

@@ -71,17 +88,17 @@ module.exports = merge({
7188
* @type {Object}
7289
*/
7390
settings: {
74-
sourceMaps: true,
91+
sourceMaps: env('SOURCEMAPS', true),
7592
styleLint: {},
7693
autoprefixer: {
7794
browsers: ['last 2 versions', '> 1%'],
7895
},
7996
browserSync: {
80-
host: 'localhost',
81-
port: 3000,
82-
proxy: 'http://localhost:8080/',
83-
open: false,
84-
reloadDelay: 500,
97+
host: env('BROWSERSYNC_HOST', 'localhost'),
98+
port: env('BROWSERSYNC_PORT', 3000),
99+
proxy: env('BROWSERSYNC_PROXY', 'http://localhost:8080/'),
100+
open: env('BROWSERSYNC_OPEN', false),
101+
reloadDelay: env('BROWSERSYNC_DELAY', 500),
85102
files: [
86103
"*.php",
87104
"app/**/*.php",

build/utils/env.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const dotenv = require('dotenv').config()
2+
3+
/**
4+
* Gets a enviourment value if it's set or default otherwise.
5+
*
6+
* @param {String} variable
7+
* @param {*} defaults
8+
*/
9+
module.exports = (variable, defaults) => {
10+
return (process.env[variable]) ? process.env[variable] : defaults
11+
}

config/app.js

-18
This file was deleted.

config/app.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"assets": {
3+
"app": [
4+
"./resources/assets/js/app.js",
5+
"./resources/assets/sass/app.scss"
6+
]
7+
}
8+
}

0 commit comments

Comments
 (0)