forked from PrestaShop/hummingbird
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.vars.js
More file actions
67 lines (56 loc) · 1.52 KB
/
webpack.vars.js
File metadata and controls
67 lines (56 loc) · 1.52 KB
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
const fs = require('fs');
const path = require('path');
const themeDev = path.resolve(__dirname, '../src');
const envFilePath = './webpack/.env';
if (fs.existsSync(envFilePath)) {
require('dotenv').config({path: envFilePath});
}
const {
PORT: port = null,
PUBLIC_PATH: publicPath = null,
SERVER_ADDRESS: serverAddress = null,
SITE_URL: siteURL = null,
} = process.env;
const entriesArray = {
theme: ['scss', 'ts'],
error: ['scss'],
theme_rtl: ['scss'],
error_rtl: ['scss'],
rtl: ['scss'],
};
exports.webpackVars = {
themeDev,
publicPath,
serverAddress,
siteURL,
port,
entriesArray,
getEntry: (entries) => {
const resultEntries = {};
for (const entry in entries) {
const files = [];
if (!entries.hasOwnProperty(entry)) {
continue;
}
for (const ext in entries[entry]) {
const extension = entries[entry][ext];
files.push(path.resolve(themeDev, `./${extension === 'ts' ? 'js' : extension}/${entry}.${extension}`));
}
resultEntries[entry] = files;
}
return resultEntries;
},
getOutput: ({
mode, publicPath, siteURL, port, serverAddress,
}) => ({
filename: 'js/[name].js',
chunkFilename: mode === 'production' ? 'js/[chunkhash].js' : 'js/[id].js',
path: path.resolve(themeDev, '../assets'),
publicPath: mode === 'production' ? '../' : `${serverAddress === 'localhost' ? siteURL : `${siteURL}:${port}`}${publicPath}`,
pathinfo: false,
library: {
name: 'Theme',
type: 'window',
}
}),
};