-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
126 lines (112 loc) · 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
124
125
126
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ROOT = path.resolve(__dirname, 'src');
const DESTINATION = path.resolve(__dirname, 'dist');
const pkg = require('./package.json');
const sharedConfig = {
context: ROOT,
mode: process.env.BUILD_MODE || 'development',
plugins: [new MiniCssExtractPlugin()],
output: {
path: DESTINATION,
filename: '[name].js',
library: pkg.name,
libraryTarget: 'umd',
publicPath: '/dist/',
umdNamedDefine: true,
},
module: {
rules: [
/****************
* PRE-LOADERS
*****************/
{
enforce: 'pre',
test: /\.tsx?$/,
exclude: /node_modules/,
use: 'tslint-loader',
},
/****************
* LOADERS
*****************/
{
test: /\.tsx?$/,
exclude: [/node_modules/],
use: 'ts-loader',
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
ref: true,
svgo: false,
},
},
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(ttf|png|jpe?g|gif)$/i,
use: [
{
loader: 'url-loader',
},
],
},
],
},
// devtool: 'cheap-module-source-map',
devServer: {},
};
const libraryConfig = {
...sharedConfig,
entry: {
index: 'index.tsx',
},
resolve: {
extensions: ['.ts', '.js', '.tsx'],
modules: [ROOT, 'node_modules'],
alias: {
react: path.resolve(__dirname, './node_modules/react'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
},
},
externals: {
// Don't bundle react or react-dom
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'React',
root: 'React',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'ReactDOM',
root: 'ReactDOM',
},
},
};
const demoConfig = {
...sharedConfig,
entry: {
demo: 'demo/main.tsx',
},
resolve: {
extensions: ['.ts', '.js', '.tsx'],
modules: [ROOT, 'node_modules'],
},
plugins: [
...sharedConfig.plugins,
new CopyPlugin({
patterns: [{ from: 'demo/index.html' }, { from: 'demo/favicon.ico' }],
}),
],
};
module.exports = [libraryConfig, demoConfig];