Skip to content

Commit 3814431

Browse files
committed
multiple webpack config, reactjs app config for multiple env
1 parent 9b6ed94 commit 3814431

19 files changed

+567
-104
lines changed

app/Http/Controllers/HomeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function index()
2626
try {
2727
// Get the correct hashed bundle JS file
2828
// TODO: Find a better way to fetch hash bundle.js
29-
$jsonBundle = json_decode(file_get_contents(base_path('webpack.manifest.json')), true);
29+
$jsonBundle = json_decode(file_get_contents(base_path('webpack.' . app()->environment() . '.manifest.json')), true);
3030
$bundleJS = $jsonBundle['bundle']['js'];
3131

3232
$jsonDll = json_decode(file_get_contents(base_path('webpack.dll.manifest.json')), true);

deploy/sources.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Only files and folders listed here will be synced
2-
SOURCES="app bootstrap config database public resources storage tests artisan composer.json composer.lock webpack.dll.manifest.json webpack.manifest.json"
2+
SOURCES="app bootstrap config database public resources storage tests artisan composer.json composer.lock webpack.dll.manifest.json webpack.production.manifest.json webpack.staging.manifest.json"

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"laravel-elixir": "^6.0.0-9",
2020
"style-loader": "^0.13.1",
2121
"webpack": "^1.13.2",
22-
"webpack-cleanup-plugin": "^0.4.1",
2322
"webpack-dev-middleware": "^1.8.4",
2423
"webpack-uglify-js-plugin": "^1.1.9"
2524
},

public/js/bundle-dev-f367f2d1d8636e4066e8.js

+374
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bundle-production-467b4520ffd9580a6726.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bundle-production-467b4520ffd9580a6726.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bundle-7a00dd586bb7812cc737.js public/js/bundle-staging-c32d0b7629c584b4fb7e.js

+47-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/app/configs/dev.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* dev config
3+
*
4+
* @date 30/10/2016
5+
* @author Mosufy <[email protected]>
6+
* @copyright Copyright (c) Mosufy
7+
*/
8+
9+
module.exports = {
10+
api : {
11+
host : 'https://lumenapi.local/v1',
12+
clientId: '6fC2745co07D4yW7X9saRHpJcE0sm0MT',
13+
clientSecret: 'KLqMw5D7g1c6KX23I72hx5ri9d16GJDW'
14+
}
15+
};

resources/app/configs/production.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* production config
3+
*
4+
* @date 30/10/2016
5+
* @author Mosufy <[email protected]>
6+
* @copyright Copyright (c) Mosufy
7+
*/
8+
9+
module.exports = {
10+
api : {
11+
host : 'https://lumen.mosufy.com/v1',
12+
clientId: '6fC2745co07D4yW7X9saRHpJcE0sm0MT',
13+
clientSecret: 'KLqMw5D7g1c6KX23I72hx5ri9d16GJDW'
14+
}
15+
};

resources/app/configs/staging.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* staging config
3+
*
4+
* @date 30/10/2016
5+
* @author Mosufy <[email protected]>
6+
* @copyright Copyright (c) Mosufy
7+
*/
8+
9+
module.exports = {
10+
api : {
11+
host : 'https://lumen.staging.mosufy.com/v1',
12+
clientId: '6fC2745co07D4yW7X9saRHpJcE0sm0MT',
13+
clientSecret: 'KLqMw5D7g1c6KX23I72hx5ri9d16GJDW'
14+
}
15+
};

resources/app/helpers/constant.js

-18
This file was deleted.

resources/app/helpers/sdk.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
* @copyright Copyright (c) Mosufy
99
*/
1010

11-
import Constant from './../helpers/constant';
1211
import axios from 'axios';
1312

13+
const apiHost = process.env.API_HOST || 'https://lumenapi.local/v1';
14+
const apiClientId = process.env.API_CLIENT_ID || '6fC2745co07D4yW7X9saRHpJcE0sm0MT';
15+
const apiClientSecret = process.env.API_CLIENT_SECRET || 'KLqMw5D7g1c6KX23I72hx5ri9d16GJDW';
16+
1417
const config = (accessToken = '') => {
1518
return ({
1619
headers: {'Authorization': 'Bearer ' + accessToken}
@@ -23,10 +26,10 @@ const config = (accessToken = '') => {
2326
* @returns AxiosPromise
2427
*/
2528
export function generateClientAccessToken() {
26-
return axios.post(Constant.apiUrl + '/oauth/access_token/client', {
29+
return axios.post(apiHost + '/oauth/access_token/client', {
2730
grant_type: 'client_credentials',
28-
client_id: Constant.clientId,
29-
client_secret: Constant.clientSecret,
31+
client_id: apiClientId,
32+
client_secret: apiClientSecret,
3033
scope: 'role.app'
3134
});
3235
}
@@ -40,10 +43,10 @@ export function generateClientAccessToken() {
4043
* @returns AxiosPromise
4144
*/
4245
export function generateUserAccessToken(clientAccessToken, username, password) {
43-
return axios.post(Constant.apiUrl + '/oauth/access_token', {
46+
return axios.post(apiHost + '/oauth/access_token', {
4447
grant_type: 'password',
45-
client_id: Constant.clientId,
46-
client_secret: Constant.clientSecret,
48+
client_id: apiClientId,
49+
client_secret: apiClientSecret,
4750
username,
4851
password,
4952
scope: 'role.user'
@@ -60,7 +63,7 @@ export function generateUserAccessToken(clientAccessToken, username, password) {
6063
* @returns AxiosPromise
6164
*/
6265
export function signup(clientAccessToken, email, password, name) {
63-
return axios.post(Constant.apiUrl + '/account', {
66+
return axios.post(apiHost + '/account', {
6467
email,
6568
password,
6669
name
@@ -74,7 +77,7 @@ export function signup(clientAccessToken, email, password, name) {
7477
* @returns AxiosPromise
7578
*/
7679
export function getUserData(accessToken) {
77-
return axios.get(Constant.apiUrl + '/account', config(accessToken));
80+
return axios.get(apiHost + '/account', config(accessToken));
7881
}
7982

8083
/**
@@ -85,28 +88,28 @@ export function getUserData(accessToken) {
8588
* @returns AxiosPromise
8689
*/
8790
export function refreshToken(clientAccessToken, refreshToken) {
88-
return axios.post(Constant.apiUrl + '/oauth/access_token', {
91+
return axios.post(apiHost + '/oauth/access_token', {
8992
grant_type: 'refresh_token',
90-
client_id: Constant.clientId,
91-
client_secret: Constant.clientSecret,
93+
client_id: apiClientId,
94+
client_secret: apiClientSecret,
9295
refresh_token: refreshToken
9396
}, config(clientAccessToken));
9497
}
9598

9699
export function getTodos(accessToken) {
97-
return axios.get(Constant.apiUrl + '/todos', config(accessToken));
100+
return axios.get(apiHost + '/todos', config(accessToken));
98101
}
99102

100103
export function insertTodo(accessToken, text) {
101-
return axios.post(Constant.apiUrl + '/todos', {
104+
return axios.post(apiHost + '/todos', {
102105
title: text
103106
}, config(accessToken));
104107
}
105108

106109
export function toggleTodo(accessToken, id) {
107-
return axios.put(Constant.apiUrl + '/todos/' + id + '/toggle', null, config(accessToken));
110+
return axios.put(apiHost + '/todos/' + id + '/toggle', null, config(accessToken));
108111
}
109112

110113
export function deleteAllTodos(accessToken) {
111-
return axios.delete(Constant.apiUrl + '/todos', config(accessToken));
114+
return axios.delete(apiHost + '/todos', config(accessToken));
112115
}

webpack.config.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
var path = require("path");
1010
var webpack = require('webpack');
1111
var AssetsPlugin = require('assets-webpack-plugin');
12-
var WebpackCleanupPlugin = require('webpack-cleanup-plugin');
1312

1413
module.exports = {
1514
cache: true,
@@ -19,7 +18,7 @@ module.exports = {
1918
devtool: 'eval',
2019
output: {
2120
path: path.join(__dirname, "public", "js"),
22-
filename: '[name]-[hash].js'
21+
filename: '[name]-dev-[hash].js'
2322
},
2423
resolve: {
2524
extensions: ['', '.js', '.jsx']
@@ -41,15 +40,19 @@ module.exports = {
4140
]
4241
},
4342
plugins: [
43+
new webpack.DefinePlugin({
44+
'process.env': {
45+
'API_HOST': JSON.stringify('https://lumenapi.local/v1'),
46+
'API_CLIENT_ID': JSON.stringify('6fC2745co07D4yW7X9saRHpJcE0sm0MT'),
47+
'API_CLIENT_SECRET': JSON.stringify('KLqMw5D7g1c6KX23I72hx5ri9d16GJDW')
48+
}
49+
}),
4450
new webpack.DllReferencePlugin({
4551
context: ".",
4652
manifest: require(path.join(__dirname, 'public', 'js', 'dll', 'vendor-manifest.json'))
4753
}),
4854
new AssetsPlugin({
49-
filename: 'webpack.manifest.json'
50-
}),
51-
new WebpackCleanupPlugin({
52-
exclude: ["bootstrap.min.js", "jquery.min.js", "dll/*"],
55+
filename: 'webpack.local.manifest.json'
5356
})
5457
]
5558
};

webpack.local.manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"bundle":{"js":"bundle-dev-f367f2d1d8636e4066e8.js"}}

webpack.manifest.json

-1
This file was deleted.

webpack.production.config.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
var path = require("path");
1010
var webpack = require('webpack');
1111
var AssetsPlugin = require('assets-webpack-plugin');
12-
var WebpackCleanupPlugin = require('webpack-cleanup-plugin');
1312

1413
module.exports = {
1514
cache: true,
@@ -19,7 +18,7 @@ module.exports = {
1918
devtool: 'cheap-module-source-map',
2019
output: {
2120
path: path.join(__dirname, "public", "js"),
22-
filename: '[name]-[hash].js'
21+
filename: '[name]-production-[hash].js'
2322
},
2423
resolve: {
2524
extensions: ['', '.js', '.jsx']
@@ -48,18 +47,18 @@ module.exports = {
4847
}),
4948
new webpack.DefinePlugin({
5049
'process.env': {
51-
'NODE_ENV': JSON.stringify('production')
50+
'NODE_ENV': JSON.stringify('production'),
51+
'API_HOST': JSON.stringify('https://lumen.mosufy.com/v1'),
52+
'API_CLIENT_ID': JSON.stringify('6fC2745co07D4yW7X9saRHpJcE0sm0MT'),
53+
'API_CLIENT_SECRET': JSON.stringify('KLqMw5D7g1c6KX23I72hx5ri9d16GJDW')
5254
}
5355
}),
5456
new webpack.DllReferencePlugin({
5557
context: ".",
5658
manifest: require(path.join(__dirname, 'public', 'js', 'dll', 'vendor-manifest.json'))
5759
}),
5860
new AssetsPlugin({
59-
filename: 'webpack.manifest.json'
60-
}),
61-
new WebpackCleanupPlugin({
62-
exclude: ["bootstrap.min.js", "jquery.min.js", "dll/*"],
61+
filename: 'webpack.production.manifest.json'
6362
})
6463
]
6564
};

webpack.production.manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"bundle":{"js":"bundle-production-467b4520ffd9580a6726.js"}}

webpack.staging.config.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* webpack.config.js
3+
*
4+
* @date 14/10/2016
5+
* @author Mosufy <[email protected]>
6+
* @copyright Copyright (c) Mosufy
7+
*/
8+
9+
var path = require("path");
10+
var webpack = require('webpack');
11+
var AssetsPlugin = require('assets-webpack-plugin');
12+
13+
module.exports = {
14+
cache: true,
15+
entry: {
16+
bundle: ["./resources/app/index.js"]
17+
},
18+
devtool: 'eval',
19+
output: {
20+
path: path.join(__dirname, "public", "js"),
21+
filename: '[name]-staging-[hash].js'
22+
},
23+
resolve: {
24+
extensions: ['', '.js', '.jsx']
25+
},
26+
module: {
27+
loaders: [
28+
{
29+
test: /\.jsx?$/,
30+
exclude: /node_modules/,
31+
loader: 'babel',
32+
// include: [
33+
// path.join(__dirname, "public")
34+
// ],
35+
query: {
36+
cacheDirectory: true,
37+
presets: ['es2015', 'stage-0', 'react']
38+
}
39+
}
40+
]
41+
},
42+
plugins: [
43+
new webpack.DefinePlugin({
44+
'process.env': {
45+
'API_HOST': JSON.stringify('https://lumen.staging.mosufy.com/v1'),
46+
'API_CLIENT_ID': JSON.stringify('6fC2745co07D4yW7X9saRHpJcE0sm0MT'),
47+
'API_CLIENT_SECRET': JSON.stringify('KLqMw5D7g1c6KX23I72hx5ri9d16GJDW')
48+
}
49+
}),
50+
new webpack.DllReferencePlugin({
51+
context: ".",
52+
manifest: require(path.join(__dirname, 'public', 'js', 'dll', 'vendor-manifest.json'))
53+
}),
54+
new AssetsPlugin({
55+
filename: 'webpack.staging.manifest.json'
56+
})
57+
]
58+
};

webpack.staging.manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"bundle":{"js":"bundle-staging-c32d0b7629c584b4fb7e.js"}}

0 commit comments

Comments
 (0)