forked from johnisr/common-components-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.config.ts
160 lines (156 loc) · 3.9 KB
/
webpack.production.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
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
import path from "path";
import { Configuration, HotModuleReplacementPlugin, optimize } from "webpack";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
const jsonImporter = require("node-sass-json-importer");
const globalStylesRegex = /\.(sass|scss|css)$/i;
const localStylesRegex = /\.module\.(sass|scss|css)$/i;
const config: Configuration = {
mode: "production",
entry: path.resolve(__dirname, "./src/index.js"),
module: {
rules: [
{
test: /\.(tsx|jsx|js)?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
},
{
test: globalStylesRegex,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: "../",
},
},
{
loader: "css-loader",
options: {
importLoaders: 2,
modules: {
auto: localStylesRegex,
localIdentName: "[hash:base64:6]",
},
},
},
"postcss-loader",
{
loader: "sass-loader",
options: {
sassOptions: {
// adds the ability to import JSON files in to SASS/SCSS variables
// currently used with `css-vars.json` for importing colour variables to SASS
importer: jsonImporter(),
},
},
},
],
sideEffects: true,
},
{
test: /\.gif/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "file-loader",
options: {
limit: 10000,
mimetype: "image/gif",
},
},
},
{
test: /\.jpg/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "file-loader",
options: {
limit: 10000,
mimetype: "image/jpg",
},
},
},
{
test: /\.png/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "file-loader",
options: {
limit: 10000,
mimetype: "image/png",
name: "[name].[ext]",
},
},
},
// treats dependencies with type: "module" the same as js files
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
],
},
resolve: {
extensions: ["*", ".ts", ".tsx", ".js", ".jsx"],
},
output: {
publicPath: "/",
path: path.resolve(__dirname, "./dist"),
filename: "bundle.js",
libraryTarget: "umd",
libraryExport: "default",
library: "validere-common",
},
externals: {
// Use external version of React
react: {
commonjs: "react",
commonjs2: "react",
amd: "react",
root: "React",
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "react-dom",
root: "ReactDOM",
},
},
plugins: [
new HotModuleReplacementPlugin(),
new CleanWebpackPlugin(),
new optimize.AggressiveMergingPlugin(), //Merge chunks
new MiniCssExtractPlugin(),
],
devServer: {
static: {
directory: "./dist",
},
hot: true,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: true,
parallel: true,
}),
new CssMinimizerPlugin(),
],
},
};
export default config;