-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
113 lines (106 loc) · 3.1 KB
/
webpack.config.ts
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
import {lstatSync, readdirSync} from 'fs';
import {join, basename} from 'path';
import {Configuration} from 'webpack';
import safeRequire from 'safe-require';
import autoprefixer from 'autoprefixer';
import JsxstylePlugin from 'jsxstyle-webpack-plugin';
import ManifestPlugin from 'webpack-manifest-plugin';
import MiniCSSExtractPlugin from 'mini-css-extract-plugin';
import postCSSDiscardDuplicates from 'postcss-discard-duplicates';
const isDev = process.env.NODE_ENV === 'development';
const isDir = (source: string) => lstatSync(source).isDirectory();
const directory = join(__dirname, 'packages');
const packages = readdirSync(directory)
.map(name => join(directory, name))
.filter(isDir)
.filter(dir => {
const pkg = safeRequire(join(dir, 'package.json'));
return pkg && pkg.scripts && pkg.scripts['dev:server'];
});
const outputPath = isDev ? 'tmp' : 'dist';
const configs: Configuration[] = packages.map(
(path): Configuration => {
const name = basename(path);
return {
name: `client:${name}`,
mode: isDev ? 'development' : 'production',
cache: isDev,
entry: {
[name]: `./packages/${name}`
},
watch: isDev,
output: {
path: join(path, outputPath),
filename: isDev ? `[name].bundle.js` : `[name].[contenthash].bundle.js`,
publicPath: '/_/'
},
module: {
rules: [
{
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/env',
{
corejs: '3',
modules: false,
targets: 'last 1 version or > 1%',
useBuiltIns: 'entry'
}
],
'@babel/react',
'@babel/typescript'
]
}
},
{
loader: JsxstylePlugin.loader,
options: {
classNameFormat: 'hash'
}
}
]
},
{
use: [
MiniCSSExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [postCSSDiscardDuplicates(), autoprefixer()],
sourceMap: true
}
}
],
test: /\.css$/
}
]
},
plugins: [
new JsxstylePlugin(),
new ManifestPlugin(),
new MiniCSSExtractPlugin({
filename: isDev
? '[name].bundle.css'
: '[name].[contenthash].bundle.css'
})
],
resolve: {
extensions: ['.mjs', '.js', '.ts', '.tsx']
},
devtool: isDev ? 'eval-source-map' : 'source-map'
};
}
);
export default configs;