-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
105 lines (101 loc) · 2.54 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
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const path = require('path')
const webpack = require('webpack')
const devServer = {
port: 8082,
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' },
static: { directory: path.join(__dirname, 'dev') },
}
const styleLoader = {
loader: 'style-loader',
options: { injectType: 'singletonStyleTag', attributes: { v: '@botsquad/web-client' } },
}
require('dotenv').config({ path: './.devenv' })
module.exports = {
mode: 'development',
target: 'web',
devtool: 'cheap-module-source-map',
devServer,
entry: {
main: './src/index',
example: './dev/example',
operator: './dev/operator',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'umd',
library: '@botsquad/web-client',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['node_modules'],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
{
test: [/\.jsx?$/],
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
},
},
'webpack-conditional-loader',
],
},
{
test: /\.html$/,
loader: 'raw-loader',
},
{
test: /\.scss$/,
use: [styleLoader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /[^min]\.css$/,
use: [styleLoader, 'css-loader'],
},
{
test: /\.min\.css$/,
use: [styleLoader, 'css-loader'],
},
{
test: /\.(eot|svg|ttf|gif|png|jpg|woff|woff2)$/,
loader: 'url-loader',
},
],
},
plugins: [
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
new ForkTsCheckerWebpackPlugin(),
new ESLintPlugin({ extensions: ['js', 'ts', 'tsx'], threads: true, lintDirtyModulesOnly: true }),
],
}
if (process.env.ANALYZE === 'true') {
console.log('** Enabling bundle analyzer')
module.exports.plugins.push(new BundleAnalyzerPlugin())
}