-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
125 lines (119 loc) · 2.9 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
124
125
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const webpack = require('webpack')
const dotenv = require('dotenv')
const buildTarget = process.env.BUILD_TARGET || 'web'
const isProduction = process.env.NODE_ENV === 'production'
const isWeb = buildTarget === 'web'
const version = require('./package.json').version
const entry = {
main: ['./src/index.tsx', './src/main.css'],
}
const config = {
entry: entry,
target: 'web',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: isWeb ? '[name].[chunkhash:12].js' : '[name].js',
},
mode: isProduction ? 'production' : 'development',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
fallback: {
fs: false,
path: false,
os: false,
},
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
},
{
test: /\.(css)$/,
use: isProduction ? [MiniCssExtractPlugin.loader, 'css-loader'] : ['style-loader', 'css-loader'],
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
{
test: /\.(png|jp(e*)g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[hash]-[name].[ext]',
},
},
],
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-url-loader',
options: {
limit: 10000,
name: 'images/[hash]-[name].[ext]',
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
// it will automatically pick up key values from .env file
'process.env': JSON.stringify(dotenv.config().parsed),
}),
new CopyWebpackPlugin({
patterns: [
{ from: './target/shared' },
{
from: `./target/${buildTarget}`,
globOptions: {
ignore: ['**/*index.html'],
},
},
],
}),
new HtmlWebpackPlugin({
template: `./target/${buildTarget}/index.html`,
}),
new MiniCssExtractPlugin({
filename: isWeb ? '[name].[contenthash].css' : '[name].css',
}),
new webpack.EnvironmentPlugin({
BUILD_TARGET: 'web',
VERSION: version,
}),
],
devtool: isWeb ? 'source-map' : false,
stats: {
warnings: false,
},
}
if (isProduction) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
})
)
}
module.exports = config