summaryrefslogtreecommitdiff
path: root/webpack.config.ts
blob: 0fdc5aec503721807600ddec316cac31f57b5701 (plain)
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
/**
 * webpack config
 */

import * as webpack from 'webpack';
const StringReplacePlugin = require('string-replace-webpack-plugin');
const constants = require('./src/const.json');

const env = process.env.NODE_ENV;
const isProduction = env === 'production';

const pack: webpack.Configuration = {
	entry: {
		'desktop': './src/web/app/desktop/script.js',
		'mobile': './src/web/app/mobile/script.js',
		'dev': './src/web/app/dev/script.js',
		'auth': './src/web/app/auth/script.js'
	},
	module: {
		rules: [
			{
				enforce: 'pre',
				test: /\.tag$/,
				exclude: /node_modules/,
				loader: StringReplacePlugin.replace({
					replacements: [
						{ pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground },
						{ pattern: /\$theme\-color/g, replacement: () => constants.themeColor },
					]
				})
			},
			{
				test: /\.tag$/,
				exclude: /node_modules/,
				loader: 'riot-tag-loader',
				query: {
					hot: false,
					style: 'stylus',
					expr: false,
					compact: true,
					parserOptions: {
						style: {
							compress: true
						}
					}
				}
			},
			{
				test: /\.styl$/,
				exclude: /node_modules/,
				use: [
					{ loader: 'style-loader' },
					{ loader: 'css-loader' },
					{ loader: 'stylus-loader' }
				]
			}
		]
	},
	plugins: [
		new webpack.DefinePlugin({
			CONFIG: {
				themeColor: JSON.stringify(constants.themeColor)
			}
		}),
		new StringReplacePlugin()
	],
	output: {
		filename: '[name]/script.js'
	}
};

if (isProduction) {
	pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
}

module.exports = pack;