forked from sneas/img-comparison-slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
134 lines (128 loc) · 2.97 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
const { merge } = require('webpack-merge');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const indexParameters = require('./public/templateParameters/index');
const commonConfig = {
mode: 'production',
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'css-loader',
options: {
sourceMap: false,
},
},
{
loader: 'sass-loader',
},
],
},
{
test: /images\/.+\.(webp|svg)$/i,
loader: 'file-loader',
options: {
name: 'images/[name].[ext]',
esModule: false,
},
},
{
test: /src\/.+\.html/,
loader: 'html-loader',
},
{
test: /favicon\.svg?$/,
loader: 'file-loader',
options: {
esModule: false,
},
},
{
test: /\.hbs$/,
loader: 'handlebars-loader',
options: {
query: { inlineRequires: '/public/' },
},
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'source-map',
plugins: [
new CopyWebpackPlugin({
patterns: [{ from: 'src/assets', to: '' }],
}),
],
};
const demoConfig = ({ favicon = 'public/favicon.svg' } = {}) => {
const htmlOptions = {
inject: true,
favicon,
};
return {
plugins: [
new HtmlWebpackPlugin({
template: './public/index.hbs',
filename: 'index.html',
templateParameters: indexParameters,
...htmlOptions,
}),
new HtmlWebpackPlugin({
template: './public/examples.hbs',
filename: 'examples.html',
...htmlOptions,
}),
new CopyWebpackPlugin({
patterns: [{ from: 'public/static', to: '' }],
}),
new CopyWebpackPlugin({
patterns: [{ from: 'public/images', to: 'images' }],
}),
new CopyWebpackPlugin({
patterns: [{ from: 'public/main.css', to: 'main.css' }],
}),
],
output: {
path: path.resolve(__dirname, 'demo'),
},
devServer: {
host: process.env.HOST ?? '0.0.0.0',
useLocalIp: process.env.NO_LOCAL_IP !== 'true',
},
};
};
const devConfig = {
mode: 'development',
};
const prodConfig = {};
module.exports = (env) => {
switch (true) {
case env.development:
return merge(
commonConfig,
demoConfig({ favicon: 'public/favicon-dev.svg' }),
devConfig
);
case env.demo:
return merge(commonConfig, demoConfig());
case env.production:
return merge(commonConfig, prodConfig);
default:
throw new Error('No matching configuration was found!');
}
};