-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
105 lines (99 loc) · 3.27 KB
/
webpack.config.js
File metadata and controls
105 lines (99 loc) · 3.27 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const webpack = require('webpack');
const DEVELOPMENT_API_BASE_URL = '/api' // base URL of your local API. Use /api if you want to use webpack proxy, else use http://localhost:3000 (frontend origin http://localhost:8080 shall then be authorized by the API cors)
const PRODUCTION_API_BASE_URL = 'https://your-app-name.azurewebsites.net'; // to be changed to point to the URL of your API
const DEVELOPMENT_PATH_PREFIX = '/'; // normally not to be changed, your assets should be provided directly within /dist/ (and not /dist/mymovies/ e.g.)
const PRODUCTION_PATH_PREFIX = '/motion-provider/'; // e.g. '/mymovies/' if you deploy to GitHub Pages as a Project site : mymovies would be the repo name
const buildMode = process.argv[process.argv.indexOf('--mode') + 1];
const isProductionBuild = buildMode === 'production';
const API_BASE_URL = isProductionBuild ? PRODUCTION_API_BASE_URL : DEVELOPMENT_API_BASE_URL;
const PATH_PREFIX = isProductionBuild ? PRODUCTION_PATH_PREFIX : DEVELOPMENT_PATH_PREFIX;
module.exports = {
mode: 'none',
entry: './src/index.js',
output: {
path: `${__dirname}/dist`,
filename: 'bundle.js',
publicPath: PATH_PREFIX,
},
devtool: 'eval-source-map',
devServer: {
server: 'https',
static: {
directory: path.join(__dirname, 'dist'),
},
client: {
overlay: {
errors: true,
warnings: false,
},
},
port: 8080,
// host: 'localhost',
host: '0.0.0.0',
allowedHosts: 'all',
open: true, // open the default browser
hot: true,
historyApiFallback: true, // serve index.html instead of routes leading to no specific ressource
proxy: {
'/api': {
target: 'http://localhost:3000',
pathRewrite: { '^/api': '' },
},
},
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
// emits a separate file and exports the URLs => works for import in JS and url in CSS
// default condition: a file with size less than 8kb will be treated as a inline
// module type and resource module type otherwise
{
test: /\.(png|jpg|gif|svg|mp3|mpe?g)$/,
type: 'asset/resource',
},
// in html file, emits files in output directory
// and replace the src with the final path (to deal with svg, img...)
{
test: /\.html$/i,
loader: 'html-loader',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
},
],
],
},
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
publicPath: PATH_PREFIX,
}),
new ESLintPlugin(),
new webpack.DefinePlugin({
'process.env.BUILD_MODE': JSON.stringify(buildMode),
'process.env.API_BASE_URL': JSON.stringify(API_BASE_URL),
'process.env.PATH_PREFIX': JSON.stringify(PATH_PREFIX),
}),
],
};