-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.babel.js
127 lines (120 loc) · 3.31 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
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
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const production = process.env.NODE_ENV === 'production';
const OUTPUT_PATH = path.resolve(__dirname, 'dist');
const config = {
mode: production ? 'production' : 'development',
devtool: production ? 'none' : 'source-map',
resolve: {
mainFiles: ['index'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.js$/,
include: /node_modules/,
loader: 'strip-sourcemap-loader',
enforce: 'pre',
},
{
test: /\.[jt]sx?$/,
include: path.resolve(__dirname, 'src'),
use: {
loader: 'babel-loader',
query: {
cacheDirectory: false,
},
},
},
{
test: /\.css$/,
exclude: [
/node_modules/,
],
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: 'pyrene-[name]__[local]--[hash:base64:10]',
},
sourceMap: !production,
},
},
'postcss-loader',
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.(woff|woff2)$/,
loader: 'url-loader',
},
],
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: process.env.NODE_ENV === 'debug' ? 'server' : 'disabled',
}),
new MiniCssExtractPlugin({
moduleFilename: ({ name }) => (name === 'main' ? 'pyrene.css' : 'pyrene.[name].css'),
}),
new OptimizeCSSAssetsPlugin({}),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/styles/colors.css', to: OUTPUT_PATH, flatten: true },
],
}),
new ForkTsCheckerWebpackPlugin({
// Options as defined in: https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/master/examples/babel-loader
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
}),
],
optimization: {
minimizer: [
new TerserPlugin({
include: 'pyrene.min.js',
cache: true,
parallel: true,
sourceMap: !production,
}),
],
},
output: {
path: OUTPUT_PATH,
filename: (chunkData) => (chunkData.chunk.name === 'main' ? 'pyrene.js' : 'pyrene.[name].js'),
library: 'pyrene',
libraryTarget: 'umd',
},
externals: ['react', 'react-dom', 'moment', 'moment-timezone'],
};
if (production) {
console.warn('webpack is running in production mode\n'); // eslint-disable-line no-console
config.entry = {
main: './src/index.ts',
min: './src/index.ts',
};
} else {
console.warn('webpack is running in development mode\n'); // eslint-disable-line no-console
config.entry = {
main: './src/index.ts',
min: './src/index.ts',
dev: './src/index.ts',
examples: './src/examples/index.ts',
};
}
export default config;