-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.config.babel.js
101 lines (98 loc) · 2.45 KB
/
webpack.config.babel.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
import fs from 'fs'
import path from 'path'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import config from './package.json'
export default {
mode: 'production',
devtool: 'source-map',
entry: {
formol: ['./src'],
...fs
.readdirSync(path.join(__dirname, 'src', 'sass'))
.reduce((themes, theme) => {
if (theme.endsWith('.sass')) {
themes[theme.slice(0, -5)] = path.join(
__dirname,
'src',
'sass',
theme
)
}
return themes
}, {}),
},
output: {
path: path.join(__dirname, 'lib'),
publicPath: 'assets/formol/',
filename: '[name].js',
library: 'formol',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this',
},
externals: Object.keys(config.peerDependencies),
plugins: [
new MiniCssExtractPlugin({ filename: '[name].css' }),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
logLevel: 'error',
}),
],
module: {
rules: [
{
test: /\.jsx?$/,
include: path.join(__dirname, 'src'),
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
browsers: ['defaults'],
},
modules: false,
},
],
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-object-rest-spread',
['@babel/plugin-proposal-decorators', { legacy: true }],
'add-react-static-displayname',
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-transform-runtime',
],
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.sass$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: [path.join(__dirname, 'src')],
},
},
},
],
},
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx'],
},
}