forked from myBraavos/starknet-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
77 lines (70 loc) · 2.18 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
// noinspection JSUnresolvedReference, JSUnusedGlobalSymbols
import path from "path";
import fs from "fs";
const __dirname = path.resolve();
class DeclarationPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tap("DeclarationPlugin", () => {
const srcPath = path.resolve(__dirname, "dist", "src");
if (fs.existsSync(srcPath)) {
fs.readdirSync(srcPath).forEach(file => {
const filepath = path.resolve(srcPath, file);
const newFilePath = path.resolve(__dirname, "dist", file);
if (file.endsWith(".d.ts")) {
// move files to dist folder
fs.renameSync(filepath, newFilePath);
} else if (
fs.lstatSync(path.resolve(srcPath, file)).isDirectory()
) {
// move directories to dist folder
fs.cpSync(filepath, newFilePath, { recursive: true });
fs.rmdirSync(filepath, { recursive: true });
}
});
fs.rmdirSync(srcPath, { recursive: true });
}
});
}
}
// noinspection JSUnusedGlobalSymbols
export default {
mode: process.env.WEBPACK_MODE,
entry: "./src/index.ts",
experiments: {
outputModule: true,
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "dist"),
library: {
type: "module",
},
globalObject: "this",
clean: true,
publicPath: "",
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.json$/,
type: "json",
},
{
test: /\.(png|jpg|jpeg|svg|webp)$/,
type: "asset/resource",
generator: {
filename: "repository/[path][name][ext]",
},
},
],
},
plugins: [new DeclarationPlugin()],
};