-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
121 lines (110 loc) · 3.61 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
110
111
112
113
114
115
116
117
118
119
120
121
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const extractPlugin = new ExtractTextPlugin({
filename: 'bundle.css'
});
var API_URL = {
production: JSON.stringify('https://codl.dev/api/'),
development: JSON.stringify('http://localhost:8080/api/')
}
var URL = {
production: JSON.stringify('https://codl.dev/'),
development: JSON.stringify('http://localhost:3000/')
}
var environment = process.env.NODE_ENV === 'production' ? 'production' : 'development';
module.exports = {
devServer: {
historyApiFallback: true
},
//Allow to debug on actual source instead of minified
//devtool: "source-map",
//This property defines where the application starts
entry: './src/main/js/index.js',
//This property defines the file path and the file name which will be used for deploying the bundled file
output: {
path: path.join(__dirname, './src/main/webapp/dist'),
filename: 'bundle.js',
publicPath: '/'
},
//Setup loaders
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
"@babel/transform-runtime",
"@babel/proposal-class-properties"
]
}
}
},
{
test: /\.css$/,
use: extractPlugin.extract({
fallback: 'style-loader',
use: ['css-loader']
})
},
{
test: /\.html$/,
use: [{
loader: 'html-loader',
options: {
minimize: true
}
}]
},
{
test: /\.(png|jpg|gif|svg|ico)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
publicPath: '/img'
},
},
],
},
]
},
// Setup plugin to use a HTML file for serving bundled js files
plugins: [
new HtmlWebpackPlugin({
template: './src/main/resources/static/index.html',
favicon: './src/main/resources/static/img/favicon.ico',
}),
extractPlugin,
new CleanWebpackPlugin(),
new WebpackPwaManifest({
name: 'Codl',
short_name: 'Codl',
description: 'Share cool pieces of code',
background_color: '#01579b',
theme_color: '#01579b',
'theme-color': '#01579b',
start_url: '/',
icons: [
{
src: path.resolve('./src/main/resources/static/img/favicon.ico'),
sizes: [16, 24, 32, 64],
destination: path.join('img')
}
]
}),
new webpack.DefinePlugin({
'API_URL': API_URL[environment],
'URL': URL[environment]
})
]
}