forked from Iconem/search-satellite-imagery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
113 lines (101 loc) · 3.37 KB
/
webpack.common.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
const resolve = require('path').resolve;
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const smp = new SpeedMeasurePlugin();
const CompressionPlugin = require('compression-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
// For env variables passing to the frontend code (webpack replaces occurences of process.env.var by their respective value)
// Can more simply use Dotenv plugin with .env filepath and safe: true param
// Otherwise, could also use below code
// ---
// const dotenv = require('dotenv');
// // call dotenv and it will return an Object with a parsed key
// const env = dotenv.config().parsed;
// console.log(env)
// const envKeys = Object.keys(env).reduce((prev, next) => {
// prev[`process.env.${next}`] = JSON.stringify(env[next]);
// return prev;
// }, {});
// console.log('\n\n\nenv', env)
const config = smp.wrap({
entry: {
app: resolve('./src/app'),
},
output: {
library: 'App',
// clean: false,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
fallback: {
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'), // if you want to use this module also don't forget npm i crypto-browserify
},
},
module: {
rules: [
// The below rule does create sourcemaps for node_modules which do not have any like react-map-gl, ky, math-gl
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
},
{
test: /\.(ts|js)x?$/,
include: [resolve('./src')],
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/env', '@babel/react'],
},
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
// {
// test: /\.html/,
// type: 'asset/resource'
// },
// {
// test: /favicon\.svg/,
// type: 'asset/resource'
// }
],
},
// Read environment variable. Recommended way is to simply use Dotenv with .env at root of project
// https://webpack.js.org/plugins/environment-plugin/
plugins: [
new Dotenv({
path: './.env', // Path to .env file (this is the default)
safe: true, // load .env.example (defaults to "false" which does not use dotenv-safe)
systemvars: true, // Set to true if you would rather load all system variables as well (useful for CI purposes)
}),
// new CompressionPlugin(),
// Other way to add index.html to dist
// new AddAssetHtmlPlugin({ filepath: require.resolve('./index.html') }),
new CleanWebpackPlugin({
verbose: true,
dry: false,
cleanAfterEveryBuildPatterns: ['!**/favicon.svg'],
}),
new AddAssetHtmlPlugin({ filepath: require.resolve('./favicon.svg') }),
new HtmlWebpackPlugin({
template: './index.html',
inject: false,
favicon: './favicon.svg',
title: 'Search EO imagery - Iconem',
}),
],
});
// Enables bundling against src in this repo rather than the installed version
module.exports = config;