This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
forked from turbosquid/PixelSquidWeb-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
154 lines (142 loc) · 3.94 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const express = require('express');
const url = require('url');
const request = require('request');
const bodyParser = require('body-parser');
const StringReplacementPlugin = require('string-replace-webpack-plugin');
const info = require('./package.json');
const TARGET = process.env.npm_lifecycle_event;
const common = {
entry: './src/atlas_main.js',
output: {
library: 'PixelSquid',
libraryTarget: 'umd',
path: path.join(__dirname, "dist"),
filename: 'pixelsquid-atlas.js'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env']
}
},
{
test: /atlas_sprite_sheet_player.js/,
loader: StringReplacementPlugin.replace({
replacements: [
{
pattern: /<!-- @version -->/ig,
replacement: function(match, pl, offset, string) {
return info.version;
}
}
]
})
}
]
},
externals: {
jquery: "jQuery"
},
resolve: {
extensions: [".js"],
alias: {
jquery: "src/externals/jquery-1.12.3.min"
}
},
plugins: [new StringReplacementPlugin()]
}
if (TARGET === "build" || !TARGET) {
module.exports = [
merge(common, {}),
merge(common, {
entry: "./src/atlas_main_server.js",
target: "node",
output: {
filename: "pixelsquid-atlas-server.js"
}
})
]
}
if (TARGET === 'start') {
//***
//Proxy API Requests
//***
const app = express();
app.use(bodyParser.json({ type: '*/*' }));
const crossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization,Accept,Content-Type,X-Client-External-User-ID');
next();
};
app.use(crossDomain);
app.get('/api/products/:productId', function(req, res) {
var query = url.parse(req.url, true);
request({
headers: {
accept: req.headers.accept,
authorization: req.headers.authorization,
'x-client-external-user-id': req.headers['x-client-external-user-id']
},
uri: `http://api.pixelsquid.com/api/products/${req.params.productId}${query.search}`
}, function(apiErr, apiRes, apiBody) {
res.contentType('application/json');
res.send(apiBody);
});
});
app.get('/api/products', function(req, res) {
var query = url.parse(req.url, true);
request({
headers: {
accept: req.headers.accept,
authorization: req.headers.authorization,
'x-client-external-user-id': req.headers['x-client-external-user-id']
},
uri: `http://api.pixelsquid.com/api/products${query.search}`
}, function(apiErr, apiRes, apiBody) {
res.contentType('application/json');
res.send(apiBody);
});
});
app.post('/api/products/:productId/download_links', function(req, res) {
var data = req.body;
request.post({
headers: {
accept: req.headers.accept,
authorization: req.headers.authorization,
'x-client-external-user-id': req.headers['x-client-external-user-id']
},
uri: `https://api.pixelsquid.com/api/products/${req.params.productId}/download_links`,
json: req.body
}, function(apiErr, apiRes, apiBody) {
res.contentType('application/json');
res.send(apiBody);
});
});
app.listen(8081, '0.0.0.0', function() {
console.log('http://0.0.0.0:8081');
console.log('api proxy: localhost -> api.pixelsquid.com');
console.log();
});
//***
//Dev Server for Static Assets
//***
module.exports = merge(common, {
devServer: {
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: process.env.HOST,
port: process.env.PORT
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});
}