-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
123 lines (122 loc) · 3.3 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require('dotenv').config()
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const autoprefixer = require('autoprefixer')
const HtmlPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin: CleanPlugin } = require('clean-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const isDev = process.env.NODE_ENV === 'dev'
const isLocal = process.env.ENV_LOCAL
module.exports = {
mode: isDev ? 'development' : 'production',
entry: {
index: '/src/index.js'
},
output: {
filename: isDev ? '[name].bundle.js' : '[name].[hash:6].js',
chunkFilename: isDev ? '[name].bundle.js' : '[name].[chunkhash:4].js',
path: path.resolve('./dist'),
publicPath: '/'
},
node: { fs: 'empty' },
module: {
rules: [
{
test: /\.js$/,
// enforce: 'post',
include: path.resolve('./src'),
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-async-to-generator'
]
}
}
},
{
test: /\.css$/,
use: [
isDev ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
},
'css-loader'
]
},
{
test: /\.s(c|a)ss$/,
use: [
isDev ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
importLoaders: 2,
modules: {
localIdentName: !isDev
? '[folder]_[hash:base64:10]'
: '[folder]_[local]_[hash:base64:5]',
},
localsConvention: 'dashes'
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()],
}
},
'sass-loader',
]
},
{
test: /\.(jpg|png|gif)/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: isDev
? 'image/[name].[ext]'
: 'image/[name].[hash:7].[ext]'
}
}
]
},
]
},
plugins: [
!isDev && new CleanPlugin(),
!isDev && new MiniCssExtractPlugin({
filename: '[name].bundle.css'
}),
!isDev && new HtmlPlugin({
title: 'torrent to magnet',
meta: {
charset: 'utf-8',
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'
},
templateContent: `<div class="root"><input type="text" class="filepond-root" type="file"></div>`,
inject: 'body',
minify: true
}),
isDev && new webpack.HotModuleReplacementPlugin(),
isDev && new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
(!isDev && isLocal) && new BundleAnalyzerPlugin()
].filter(Boolean),
devServer: {
// contentBase: '',
disableHostCheck: true,
host: '0.0.0.0',
port: 8000,
hot: true,
historyApiFallback: true,
},
devtool: 'source-map'
}