-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
51 lines (42 loc) · 1.04 KB
/
webpack.common.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
'use strict';
require('dotenv').config();
const { DefinePlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const production = process.env.NODE_ENV === 'production'; // evals to a Boolean value
const webpackConfig = module.exports = {};
webpackConfig.entry = `${__dirname}/src/main.js`;
webpackConfig.output = {
filename: '[name].[hash].js',
path: `${__dirname}/build`,
publicPath: process.env.CDN_URL,
};
webpackConfig.plugins = [
new HtmlWebpackPlugin({
title: 'React App',
template: `${__dirname}/src/index.html`,
}),
// this makes webpack constants
new DefinePlugin({
API_URL: JSON.stringify(process.env.API_URL),
}),
];
webpackConfig.module = {};
webpackConfig.module.rules = [{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'stage-0', 'react'],
plugins: ['transform-react-jsx-source'],
cacheDirectory: true,
},
},
},
];