-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.config.js
50 lines (50 loc) · 1.36 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
import * as url from "url";
import { resolve as _resolve } from "path";
import DependencyExtractionWebpackPlugin from "@woocommerce/dependency-extraction-webpack-plugin";
import * as glob from "glob";
import path from "path";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const isProduction = process.env.NODE_ENV == "production";
// Common configuration settings
const common = {
mode: isProduction ? "production" : "development",
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
use: "ts-loader",
exclude: ["/node_modules/", "/tests/", "/vendor/"],
},
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".scss", ".sass", ".css"],
},
plugins: [
new DependencyExtractionWebpackPlugin({
injectPolyfill: true,
}),
],
};
// Blocks configuration
const blocksConfig = {
...common,
entry: glob
.sync("./blocks/src/**/!(shared)/**/index.tsx", {
ignore: ["./blocks/src/shared/**/index.tsx"],
})
.reduce((entries, file) => {
const entryName = path.basename(path.dirname(file));
entries[entryName] = `./${file}`;
return entries;
}, {}),
output: {
path: path.resolve(__dirname, "./blocks/build/"),
filename: `[name].js`,
},
};
export default [blocksConfig];