This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
84 lines (80 loc) · 2.66 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
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {resolve} = require('path');
require('dotenv').config();
const srcFolder = resolve(__dirname, 'src');
const redirectApiPattern = /(\/api\/\*)\W(http.+)(\/\:splat)\W(\d+)/g;
const API_URL = process.env.API_URL;
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: {
main: resolve(srcFolder, 'index.jsx'),
vendor: ['react', 'react-dom', 'jquery', 'semantic-ui-css'],
sw: resolve(srcFolder, 'sw.js'),
},
output: {
path: resolve('dist'),
filename: '[name].js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new HtmlWebpackPlugin({template: resolve(srcFolder, 'index.tpl.html')}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery'
}),
new webpack.EnvironmentPlugin(['API_URL', 'VAPID_PUBLIC']),
new webpack.ProvidePlugin({
Promise: 'imports-loader?this=>global!exports-loader?global.Promise!es6-promise',
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
}),
new CopyWebpackPlugin([{
from: '_redirects',
toType: 'file',
transform: function(content, path){
if (path.includes('_redirects')) {
const result = content.toString('utf8').replace(redirectApiPattern, `$1 ${API_URL}$3 $4`);
console.log('Replace _redirects', result);
return result;
}
return content;
}
}])
],
module: {
rules: [{
test: /\.(html)$/,
use: {loader: 'file-loader'},
exclude: [resolve(srcFolder, 'index.tpl.html')],
}, {
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
query: { cacheDirectory: true }, // important for performance
},
include: [srcFolder ], // important for performance!
}, {
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
}, {
test: /\.(eot|woff|woff2|ttf)$/,
use: {loader: 'file-loader'},
}, {
test: /\.(gif|png|jpe?g|svg)$/i,
use: {loader: 'file-loader'},
}],
},
devServer: {
contentBase: './dist',
proxy: {
'/api/**': {
target: `http:https://localhost:8081`,
pathRewrite: { '^/api': '' },
},
},
},
};