-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
89 lines (84 loc) · 2.51 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
const path = require('path');
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
// const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
const config = {
// context: __dirname,
// entry: ['./src/index.js'],
entry: path.resolve(__dirname, 'src', 'index.js'),
// https://webpack.js.org/configuration/devtool/#development
devtool: process.env.NODE_ENV === 'development' ? 'cheap-eval-source-map' : false,
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/' // https://webpack.js.org/guides/public-path/
},
devServer: {
hot: true,
contentBase: './public',
publicPath: 'http://localhost:3000/',
historyApiFallback: true,
port: 3000
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
stats: {
colors: true,
reasons: true,
chunks: false
},
plugins: [ // https://webpack.js.org/plugins/
// https://webpack.js.org/guides/hot-module-replacement/
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
// TODO: add this to hide env vars
new Dotenv({ // https://www.npmjs.com/package/dotenv-webpack
path: './.env', // Path to .env file (this is the default)
safe: false, // load .env.example (defaults to "false" which does not use dotenv-safe)
silent: false
})
// new HtmlWebpackPlugin({ template: './public/index.html' })
// new webpack.DefinePlugin({
// 'process.env': {
// 'NODE_ENV': JSON.stringify('production')
// }
// })
],
module: {
rules: [
{
test: /\.js$/,
// use: 'babel-loader',
exclude: /node_modules/,
loader: 'babel-loader', // https://github.com/babel/babel-loader
// include: path.resolve(__dirname, './src'),
query: {
presets: ['es2015']
},
},
{
test: /\.css$/, // /\.scss/
use: ['style-loader', 'css-loader'] // , 'sass-loader'
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: "url-loader?name=/public/images/[name].[ext]"
}
// { test: /\.png$/,
// loader: 'file'
// }
// {
// test: /\.jsx?$/,
// loader: 'babel-loader',
// include: [path.resolve('js')]
// }
]
}
};
if (process.env.NODE_ENV !== 'production') {
console.log('In development mode!');
} else {
console.info('Running in production');
}
module.exports = config;