-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.config.js
113 lines (102 loc) · 3.08 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
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const nodeEnv = process.env.NODE_ENV || 'development';
module.exports = {
devtool: false, // https://github.com/webpack/webpack/issues/1194#issuecomment-560382342
stats: {
all: false,
builtAt: true,
errors: true,
hash: true,
},
mode: nodeEnv,
entry: path.join(__dirname, 'source', 'index.ts'),
output: {
path: path.join(__dirname, 'lib'),
filename: 'index.js',
// https://stackoverflow.com/a/57287049
libraryTarget: 'umd',
library: 'react-minimal-side-navigation',
globalObject: 'this', // https://git.io/JTDXW
},
// https://git.io/JTDXB
externals: ['react', 'tailwindcss'],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
use: [
{
loader: 'babel-loader', // optimizes the JavaScript code
},
{
loader: 'ts-loader', // keep this for declaration files generation
},
],
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader, // It creates a CSS file per JS file which contains CSS
},
{
loader: 'css-loader', // Takes the CSS files and returns the CSS with imports and url(...) for Webpack
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
plugins: [require('tailwindcss'), require('autoprefixer')],
},
},
},
'resolve-url-loader', // Rewrites relative paths in url() statements
'sass-loader', // Takes the Sass/SCSS file and compiles to the CSS
],
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(), // run TSC on a separate thread
// delete previous build files
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.join(process.cwd(), `lib`)],
cleanStaleWebpackAssets: false,
verbose: true,
}),
// write css file(s) to build folder
new MiniCssExtractPlugin({filename: 'ReactMinimalSideNavigation.css'}),
],
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: ['default', {discardComments: {removeAll: true}}],
},
}),
],
},
};