-
Notifications
You must be signed in to change notification settings - Fork 712
/
webpack.build.js
171 lines (165 loc) · 3.62 KB
/
webpack.build.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
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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const RemovePlugin = require("remove-files-webpack-plugin");
const config = {
mode: "production",
};
const jsOutput = Object.assign({}, config, {
entry: ["./src/components/ImageGallery.jsx"],
output: {
path: path.resolve(__dirname, "build"),
filename: "image-gallery.js",
library: "ImageGallery",
globalObject: "this",
libraryTarget: "umd",
},
resolve: {
alias: {
src: path.resolve(__dirname, "src/"),
},
extensions: [".js", ".jsx"],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
},
],
},
externals: {
// Don't bundle react or react-dom
react: {
commonjs: "react",
commonjs2: "react",
amd: "react",
root: "React",
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "react-dom",
root: "ReactDOM",
},
},
});
const cssOutput = Object.assign({}, config, {
entry: "./styles/scss/image-gallery.scss",
output: {
path: path.resolve(__dirname, "styles/css"),
},
module: {
rules: [
{
test: /\.(css|scss)$/i,
use: [
MiniCssExtractPlugin.loader,
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "image-gallery.css",
}),
new RemovePlugin({
/**
* After compilation permanently remove empty JS files created from CSS entries.
*/
after: {
test: [
{
folder: "styles/css",
method: (absoluteItemPath) => {
return new RegExp(/\.js$/, "m").test(absoluteItemPath);
},
},
],
},
}),
],
});
const jsDemoOutput = Object.assign({}, config, {
entry: ["./example/App.jsx"],
output: {
path: path.resolve(__dirname, "demo"),
filename: "demo.mini.js",
},
resolve: {
alias: {
src: path.resolve(__dirname, "src/"),
},
extensions: [".js", ".jsx"],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "babel-loader",
},
],
},
plugins: [
new RemovePlugin({
/**
* After compilation permanently remove unused LICENSE.txt file
*/
after: {
test: [
{
folder: "demo",
method: (absoluteItemPath) => {
return new RegExp(/\.txt$/).test(absoluteItemPath);
},
},
],
},
}),
],
});
const cssDemoOutput = Object.assign({}, config, {
entry: ["./styles/scss/image-gallery.scss", "./example/App.css"],
output: {
path: path.resolve(__dirname, "demo"),
},
module: {
rules: [
{
test: /\.(css|scss)$/i,
use: [
MiniCssExtractPlugin.loader,
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "demo.mini.css",
}),
new RemovePlugin({
/**
* After compilation permanently remove empty JS files created from CSS entries.
*/
after: {
test: [
{
folder: "demo",
method: (absoluteItemPath) => {
return new RegExp(/\.js$/).test(absoluteItemPath);
},
},
],
},
}),
],
});
module.exports = [jsOutput, cssOutput, jsDemoOutput, cssDemoOutput];