-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
132 lines (111 loc) · 3.21 KB
/
webpack.config.ts
File metadata and controls
132 lines (111 loc) · 3.21 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
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
import * as path from 'path';
import * as webpack from 'webpack';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { COLORS, DEFAULTS, STYLES } from "./core/constants";
import { LANGUAGES, TYPES } from "./core/langs";
import en from "./trans/en.json";
import ru from "./trans/ru.json";
const TRANSLATIONS = {
en: "English 🇬🇧",
ru: "Русский 🇷🇺"
}
const LITERALS = {
en: en,
ru: ru
};
// For passing variables to LESS:
const LESS_VARS = {
colors: Object.keys(COLORS),
styles: Object.keys(STYLES)
};
Object.keys(DEFAULTS).forEach((value) => {
LESS_VARS["def-" + value] = DEFAULTS[value];
});
// For passing variables to PUG:
const PUG_VARS = {
colors: Object.keys(COLORS),
styles: Object.keys(STYLES),
languages: Object.keys(LANGUAGES),
types: Object.values(TYPES),
literals: LITERALS.en,
translations: TRANSLATIONS,
build: '#'
};
const config: webpack.Configuration = {
mode: 'production',
entry: "./scripts/main.ts",
resolve: {
extensions: [ '.ts', '.js' ],
},
output: {
path: path.join(__dirname, './build/'),
filename: "./all.min.js"
},
optimization: {
minimize: true
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'babel-loader',
exclude: /(node_modules|bower_components)/
},
{
test: /\.jsx?$/,
use: 'babel-loader'
},
{
test: /\.less$/,
use: [ "style-loader", "css-loader",
{
loader: "less-loader",
options: {
lessOptions: {
modifyVars: LESS_VARS
}
}
}
],
exclude: /(node_modules|bower_components)/
},
{
test: /\.css$/,
use: [
{
loader: "style-loader",
options: {
insert: 'head',
injectType: 'singletonStyleTag'
}
}, "css-loader"
]
},
{
test: /\.pug$/,
use: 'pug-loader',
exclude: /(node_modules|bower_components)/
}
]
},
plugins: [ new CleanWebpackPlugin() ]
}
module.exports = (env, argv) => {
if (argv.mode == 'development') {
config.devtool = 'eval-source-map';
} else PUG_VARS.build = process.env.build_link;
for (const literal in LITERALS) {
PUG_VARS.literals = LITERALS[literal]
const vars = JSON.stringify(PUG_VARS);
config.plugins.push(
new HtmlWebpackPlugin({
template: './pages/index.pug',
favicon: './favicon.ico',
filename: ((literal == 'en') ? 'index' : literal) + '.html',
templateParameters: JSON.parse(vars)
})
);
}
return config;
};