-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.js
100 lines (95 loc) · 2.7 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
const path = require('path');
// const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const Dotenv = require('dotenv-webpack');
//plugins [... , new NodePolyfillPlugin()]
const buildPath = './build';
// const nodeExternals = require('webpack-node-externals');
/**
* ,
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.MY_ENV': JSON.stringify(process.env.MY_ENV),
}),
new NodePolyfillPlugin()
*/
/**
*
resolve: {
fallback: {
fs: require.resolve('fs'),
net: require.resolve('net'),
util: require.resolve('util/')
},
},
*/
// externals: [nodeExternals()],
module.exports = {
entry: path.resolve(__dirname, './client/index.js'),
output: {
path: path.resolve(__dirname, buildPath),
filename: 'bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
title: 'WeatherApp',
template: 'client/html/index.html',
filename: 'index.html'
}),
new Dotenv({
path: './.env', // load this now instead of the ones in '.env'
safe: false, // load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
allowEmptyValues: false, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
systemvars: false, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: false, // hide any errors
defaults: false, // load '.env.defaults' as the default values if empty.
ignoreStub: false,
prefix: 'process.env.' // reference your env variables as 'import.meta.env.ENV_VAR'.
})
],
module: {
rules: [
{
test: /\.jsx?/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env','@babel/preset-react']
}
}
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
}
]
},
mode: process.env.NODE_ENV,
devServer: {
static: {
directory: path.resolve(__dirname, buildPath),
publicPath: 'http://localhost:8080/'
},
compress: true,
port: 8080,
proxy: [
{
context: ['/user', '/reminder'],
target: 'http://localhost:3000',
},
]
}
}