-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (72 loc) · 1.82 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
const Path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Webpack = require('webpack');
let Dotenv = require('dotenv');
module.exports = (env) => {
Dotenv = Dotenv.config({ path: Path.join(__dirname, `/.env.${Object.keys(env)[0]}`) }).parsed;
const common = {
mode: process.env.NODE_ENV,
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: Path.resolve(__dirname, 'src'),
exclude: /(node_modules | build | bundle)/,
use: ['babel-loader'],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new Webpack.DefinePlugin({
'process.env': JSON.stringify(Dotenv),
}),
],
resolve: {
modules: [Path.resolve('src'), Path.resolve('node_modules')],
extensions: ['.js', '.jsx'],
},
};
if (process.env.NODE_ENV === 'production') {
return {
...common,
entry: './src/index.js',
output: {
path: Path.resolve(__dirname, 'bundle'),
filename: 'index.js',
library: 'liber-components',
libraryTarget: 'commonjs2',
},
optimization: {
minimize: true,
},
target: 'node',
externals: ['react', 'styled-components'],
};
}
return {
...common,
entry: './src/index.dev.jsx',
output: {
path: Path.resolve(__dirname, 'dev'),
filename: 'index.js',
},
plugins: [
new HtmlWebpackPlugin({
template: Path.resolve(__dirname, 'src/index.dev.html'),
filename: 'index.html',
inject: 'body',
}),
],
devtool: 'inline-source-map',
devServer: {
compress: true,
contentBase: Path.resolve(__dirname, 'dev'),
port: process.env.SERVER_PORT,
stats: 'minimal',
},
};
};