-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
46 lines (37 loc) · 1.1 KB
/
webpack.config.js
File metadata and controls
46 lines (37 loc) · 1.1 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
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ENVIRONMENT = process.argv[process.argv.indexOf('--mode') + 1] || 'development';
const envPath = path.resolve(__dirname, `.env.${ENVIRONMENT}`);
const env = dotenv.config({ path: envPath }).parsed;
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
console.info('Environment Variables', envKeys);
module.exports = {
entry: { index: path.resolve(__dirname, 'src', 'app', 'index.js') },
output: {
clean: true,
filename: 'js/[name].js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.scss$/,
use: [{ loader: 'css-loader' }, { loader: 'sass-loader', options: { sourceMap: true } }],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
}),
new webpack.DefinePlugin(envKeys),
],
devServer: {
open: true,
},
};