-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.base.js
158 lines (144 loc) · 4.91 KB
/
webpack.base.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import path from 'path';
import { fileURLToPath } from 'url';
import remarkGfm from 'remark-gfm';
import webpack from 'webpack';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CreateFileWebpack from 'create-file-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlWebpackHarddiskPlugin from 'html-webpack-harddisk-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
const __filename = fileURLToPath(import.meta.url);
const sha = process.env.VERCEL_GITHUB_COMMIT_SHA || process.env.AWS_COMMIT_ID;
const version = sha ? sha.substr(0, 4) : 'dev';
const __dirname = path.dirname(__filename);
export default {
name: 'client',
context: path.resolve(__dirname, './app'),
output: {
path: path.resolve(__dirname, './www/built'),
publicPath: '/built/',
},
target: 'web',
stats: {
children: true,
},
devServer: {
historyApiFallback: {
index: 'www/index.html',
},
},
plugins: [
new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
}),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
PUBLIC_URL: 'http://localhost:3000',
API_HOST: 'http://localhost:9999',
Z_URL: 'https://z.molitva.app',
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[name].[contenthash].css',
}),
new webpack.NoEmitOnErrorsPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'index.html',
filename: '../index.html',
alwaysWriteToDisk: true,
}),
new HtmlWebpackHarddiskPlugin(),
new CreateFileWebpack({
path: './www/built',
fileName: 'version',
content: `"${version}"`,
}),
new CreateFileWebpack({
path: './www/built',
fileName: 'version.json',
content: `"${version}"`,
}),
new CreateFileWebpack({
path: './www',
fileName: 'version',
content: `${version}`,
}),
],
module: {
rules: [
{
test: /\.worker\.js$/,
use: {
loader: 'worker-loader',
options: { publicPath: '/built/' },
},
},
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules\/(?!capacitor-data-storage-sqlite)(?!recoil)(?!unfetch).*$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: { browsers: ['ie >= 11', 'safari > 9'] } }]],
},
},
],
},
{
test: /\.woff2?$/i,
type: 'asset/resource',
dependency: { not: ['url'] },
},
{
test: /\.(eot|svg|ttf|woff)$/,
use: 'file-loader',
},
{
test: /\.css$/, // global - without modules
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.global\.scss$/, // global - without modules
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /^((?!\.global).)*scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.mdx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
{
loader: '@mdx-js/loader',
/** @type {import('@mdx-js/loader').Options} */
options: {
providerImportSource: '@mdx-js/react',
remarkPlugins: [remarkGfm],
},
},
{
loader: 'pattern-replace-loader',
options: {
multiple: [
{ search: '(\\s)\\/\\/(\\s)', replace: '$1**//**$2', flags: 'gi' },
{ search: '(\\s)\\/(\\s)', replace: '$1**/**$2', flags: 'gi' },
],
},
},
],
},
],
},
resolve: {
modules: ['node_modules', path.resolve(__dirname, './app')],
extensions: ['.js', '.json', '.jsx', '.ts', '.tsx', '.css'],
},
};