-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
182 lines (175 loc) · 5.91 KB
/
webpack.config.js
File metadata and controls
182 lines (175 loc) · 5.91 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Copyright (c) 2011-2020 Genestack Limited
* All Rights Reserved
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF GENESTACK LIMITED
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*/
const path = require('path');
const postcssCustomProperties = require('postcss-custom-properties');
const postcssImport = require('postcss-import');
const autoprefixer = require('autoprefixer');
const calc = require('postcss-calc');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// Styleguidist has dependencies that are not traspiled and do not work in IE.
// Force babel-loader to transpile it manually.
const transpileDependencies = [
'react-dev-utils',
'ansi-regex',
'ansi-styles',
'chalk',
'strip-ansi'
];
const postCssLoaderParams = {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssImport,
postcssCustomProperties({preserve: false}),
calc(),
autoprefixer
]
}
}
};
const babelExcludePattern = new RegExp(`node_modules/(?!(${transpileDependencies.join('|')})/).*`);
const styleLoader = {
loader: 'style-loader',
options: {
esModule: false
}
};
module.exports = (env) => {
const isProduction = env.production;
return {
mode: isProduction ? 'production' : 'development',
devtool: false,
cache: true,
entry: './src/index.ts',
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
filename: isProduction ? 'index.js' : 'genestack-ui.js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
plugins: isProduction
? [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// all options are optional
filename: 'genestack-ui.css',
ignoreOrder: false // Enable to remove warnings about conflicting order
}),
new CopyPlugin({
patterns: [
{
context: path.join(__dirname, 'src'),
from: '**/*.css.d.ts',
to: path.join(__dirname, 'dist')
},
{
context: path.join(__dirname, 'src'),
from: 'variables.css',
to: path.join(__dirname, 'dist')
}
]
})
]
: [],
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, './tsconfig.build.json')
}
},
{
test: /\.js?$/,
enforce: 'pre',
loader: 'babel-loader',
exclude: babelExcludePattern,
options: {
presets: ['@babel/preset-env']
}
},
{
test: /\.module\.css/,
enforce: 'pre',
include: /src/,
use: [
...(isProduction
? [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false
}
}
]
: [styleLoader]),
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]--[hash:base64:5]'
},
importLoaders: 1
}
},
postCssLoaderParams
]
},
{
test: /\.css/,
enforce: 'pre',
exclude: /\.module\.css/,
use: [
...(isProduction
? [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false
}
}
]
: [styleLoader]),
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
postCssLoaderParams
]
},
{
test: /\.(jpe?g|png|gif|svg|woff|woff2|eot|ttf)$/i,
type: 'asset/resource'
}
]
},
externals: [
'react',
'react-dom',
'classnames',
'dom-helpers',
'downshift',
'react-popper',
'@popperjs/core',
'react-textarea-autosize',
'react-transition-group',
'simplebar',
'simplebar-react'
],
optimization: {
minimize: false
}
};
};