-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cjs
109 lines (99 loc) · 2.29 KB
/
webpack.config.cjs
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
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CreateFilePlugin = require('create-file-webpack');
const buildPath = path.resolve(__dirname, 'dist');
const isDevelopment = process.env.NODE_ENV === 'development';
Dotenv.config({ path: './.env.development' });
const cacheEnable = !isDevelopment || process.env.CACHE_ENABLE;
const assets = fs.readdirSync('src/assets/').map((filename) => {
return `"/assets/${filename}"`;
});
module.exports = {
entry: {
app: path.resolve(__dirname, './src/index.js'),
...(cacheEnable && { 'service-worker': './src/service-worker.js' }),
},
target: isDevelopment ? 'web' : 'browserslist',
output: {
path: buildPath,
filename: '[name].js',
},
module: {
rules: [
{
test: /\.(png|svg|jpg)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
},
},
{
test: /\.s?css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.hbs$/,
loader: 'handlebars-loader',
},
{
test: /\.js$/,
exclude: /(node_modules|dist)/,
use: 'babel-loader',
resolve: {
fullySpecified: false,
},
},
],
},
devServer: {
host: process.env.HOST,
port: process.env.PORT,
hot: true,
historyApiFallback: true,
static: {
directory: buildPath,
},
proxy: [
{
context: ['/api/v1'],
target: 'http://5.35.12.15:8000',
},
{
context: ['/minio-api'],
target: 'http://5.35.12.15',
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'Resto',
favicon: './src/assets/favicon.png',
base: '/',
meta: {
viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
},
}),
new MiniCssExtractPlugin({
filename: 'styles.css',
}),
new CopyWebpackPlugin({ patterns: [{ from: 'src/assets', to: 'assets' }] }),
new CreateFilePlugin({
path: buildPath,
fileName: 'assets_filenames.txt',
content: `[${assets}]`,
}),
new webpack.DefinePlugin({
'process.env.CACHE_ENABLE': cacheEnable,
}),
],
resolve: {
extensions: ['.js'],
},
};