forked from entur/tavla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
109 lines (107 loc) · 3.37 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
const path = require('path')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const Dotenv = require('dotenv-webpack')
const postcssPresetEnv = require('postcss-preset-env')
const OUTPUT_PATH = path.resolve(__dirname, 'dist')
module.exports = (env) => {
return {
mode: 'development',
entry: './src/main.tsx',
devtool: 'inline-source-map',
output: {
path: OUTPUT_PATH,
filename: '[name].[hash].js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules|sdk/,
loader: 'awesome-typescript-loader',
},
{
test: /\.jsx?$/,
exclude: /entur\/sdk/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
exclude: /mapbox-gl/,
},
},
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [postcssPresetEnv()],
},
},
],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [postcssPresetEnv()],
},
},
'sass-loader',
],
},
{
test: /\.(svg|png|jpe?g|gif|eot|webp|woff2?)$/,
loader: 'file-loader',
options: {
outputPath: 'assets/',
},
},
],
},
devServer: {
open: true,
contentBase: OUTPUT_PATH,
port: 9090,
historyApiFallback: true,
},
plugins: [
new HtmlWebPackPlugin({
template: 'src/index.html',
filename: 'index.html',
favicon: 'src/assets/images/logo.png',
}),
new Dotenv({
path: path.join(
__dirname,
`.env.${typeof env === 'string' ? env : 'staging'}`,
),
}),
],
watch: typeof env !== 'string',
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},
}
}