-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebpack.config.js
More file actions
97 lines (92 loc) · 2.75 KB
/
webpack.config.js
File metadata and controls
97 lines (92 loc) · 2.75 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
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 path = require('path');
const dotenv = require('dotenv');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = () => {
const env = dotenv.config().parsed || { API_URL: process.env.API_URL };
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
const isDevMode = process.env.NODE_ENV !== 'production';
return {
target: 'web',
entry: ['./src/index.js', './src/Themes/App.scss'],
mode: process.env.NODE_ENV || 'development',
devServer: {
publicPath: '/dist/',
port: process.env.PORT,
historyApiFallback: true,
contentBase: ['./', './public'],
},
devtool: isDevMode ? 'source-map' : '',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: require('./babel.config.json'),
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDevMode,
},
},
{ loader: 'css-loader', options: { sourceMap: true } },
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: require('sass'),
sassOptions: {
includePaths: ['./node_modules'],
},
},
},
],
},
],
},
resolve: { extensions: ['*', '.js', '.jsx'] },
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: `[name].bundle${!isDevMode ? '.[hash]' : ''}.js`,
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.s?css$/,
chunks: 'all',
enforce: true,
},
},
},
},
plugins: [
new webpack.DefinePlugin(envKeys),
new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
new OptimizeCSSAssetsPlugin(),
new MiniCssExtractPlugin({
filename: `[name].bundle${!isDevMode ? '.[hash]' : ''}.css`,
}),
new HtmlWebpackPlugin({
inject: false,
title: 'ThreeDify',
scriptLoading: 'defer',
filename: path.join(__dirname, 'public', 'index.html'),
template: path.join(__dirname, 'src', 'index.html'),
}),
],
};
};