forked from johreh/gloomycompanion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
97 lines (90 loc) · 2.37 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
const fs = require('fs');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const mode = process.env.NODE_ENV || 'development';
const styleLoader = process.env.WEBPACK_SERVE ? 'style-loader' : MiniCssExtractPlugin.loader;
module.exports = {
mode,
entry: './index',
output: {
filename: 'bundle.js',
library: 'Gloom',
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'react-hot-loader/babel',
],
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
},
{ test: /\.css$/, use: [styleLoader, 'css-loader', 'postcss-loader'] },
{
test: /\.scss$/,
use: [
styleLoader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
localsConvention: 'dashesOnly',
modules: {
localIdentName: mode === 'production' ? '[hash:base64]' : '[name]__[local]--[hash:base64:5]',
},
},
},
'postcss-loader',
'sass-loader',
],
},
{ test: /\.svg$/, use: 'svg-url-loader?limit=8192' },
{ test: /\.(jpg|ttf)$/, use: 'url-loader?limit=8192' },
],
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].css' }),
],
resolve: {
extensions: ['.js', '.json', '.jsx'],
},
externals: [
{
'firebase/app': 'firebase',
'prop-types': 'PropTypes',
react: 'React',
'react-dom': 'ReactDOM',
},
(context, request, callback) => {
if (request === './config.local') {
return fs.exists(path.resolve(__dirname, 'config.local.js'), (exists) => {
if (exists) {
return callback();
}
return callback(null, '{}');
});
}
return callback();
},
],
};
if (process.env.WEBPACK_SERVE) {
module.exports.serve = {
dev: {
publicPath: module.exports.output.publicPath,
},
};
}