-
Notifications
You must be signed in to change notification settings - Fork 31
/
webpack.config.mjs
135 lines (122 loc) · 3.38 KB
/
webpack.config.mjs
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
import './init-env.mjs' // SHOULD BE FIRST
import path from 'path'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import WriteFilePlugin from 'write-file-webpack-plugin'
import webpackBlocks from 'webpack-blocks'
import {
// postcss,
react,
// sass,
styles,
spa,
assets,
proxy,
sentry,
babel,
devServer,
} from './presets/index.mjs'
const {
addPlugins,
createConfig,
env,
entryPoint,
resolve,
setEnv,
setOutput,
sourceMaps,
when,
customConfig,
} = webpackBlocks
export default createConfig([
entryPoint({
bundle: 'index.js',
// styles: './src/sass/app.sass',
// you can add you own entries here (also check SplitChunksPlugin)
// code splitting guide: https://webpack.js.org/guides/code-splitting/
// SplitChunksPlugin: https://webpack.js.org/plugins/split-chunks-plugin/
}),
resolve({
modules: [
path.resolve(`${process.env.SOURCES_PATH}/app`),
'node_modules',
],
alias: {
'react-dom': process.env.NODE_ENV !== 'development' ? 'react-dom' : '@hot-loader/react-dom',
'@ds-frontend/cache': 'ds-frontend/packages/cache',
'@ds-frontend/api': 'ds-frontend/packages/api',
'@ds-frontend/i18n': 'ds-frontend/packages/i18n',
'@ds-frontend/queryParams': 'ds-frontend/packages/queryParams',
'@ds-frontend/redux-helpers': 'ds-frontend/packages/redux-helpers',
'@ds-frontend/resource': 'ds-frontend/packages/resource',
},
extensions: ['.js', '.jsx', '.json', '.css', '.sass', '.scss'],
}),
setOutput({
path: path.resolve(`${process.env.OUTPUT_PATH}${process.env.PUBLIC_PATH}`),
publicPath: process.env.PUBLIC_URL,
// NOTE: 'name' here is the name of entry point
filename: '[name].js',
// TODO check are we need this (HMR?)
// chunkFilename: '[id].chunk.js',
pathinfo: process.env.NODE_ENV === 'development',
}),
setEnv([
// pass env values to compile environment
'API_URL', 'AUTH_HEADER', 'MAIN_HOST',
'CACHE_STATE_KEYS', 'STORAGE_KEY', 'SENTRY_DSN', 'SENTRY_ENVIRONMENT', 'CACHE_STATE_PERSIST_KEYS', 'LIMIT',
'NODE_ENV', 'APP_NAME',
]),
addPlugins([
// clean distribution folder before compile
new CleanWebpackPlugin(),
]),
customConfig({
mode: process.env.NODE_ENV ?? 'development',
optimization: {
splitChunks: {
cacheGroups: {
// move all modules defined outside of application directory to vendor bundle
defaultVendors: {
test: function(module) {
return module.resource && module.resource.indexOf(path.resolve('src')) === -1
},
name: 'vundle',
chunks: 'all',
},
},
},
},
}),
env('development', [
devServer({
static: {
directory: path.resolve(`${process.env.OUTPUT_PATH}`),
},
port: process.env.DEV_SERVER_PORT || 3000,
host: process.env.DEV_SERVER_HOST || 'local-ip',
allowedHosts: [
'.localhost',
`.${process.env.MAIN_HOST}`,
],
hot: true,
client: {
overlay: false,
},
}),
sourceMaps('eval-source-map'),
addPlugins([
// write generated files to filesystem (for debug)
// FIXME are we realy need this???
new WriteFilePlugin(),
]),
]),
when(!process.env.SSR, [spa()]),
proxy(),
babel(),
react(),
sentry(),
// sass(),
styles(),
// postcss(),
assets(),
])