-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
116 lines (105 loc) · 3.67 KB
/
webpack.config.js
File metadata and controls
116 lines (105 loc) · 3.67 KB
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
const path = require("path");
const webpack = require("webpack");
const fs = require('fs');
class UpdateAndCopyManifestPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tap('UpdateAndCopyManifestPlugin', (compilation) => {
const packageJsonPath = path.resolve(__dirname, 'package.json');
const manifestJsonPath = path.resolve(__dirname, 'manifest.json');
const outputDir = path.resolve(__dirname, 'dist', 'circuit-sketcher');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
const manifestJson = JSON.parse(fs.readFileSync(manifestJsonPath, 'utf8'));
manifestJson.version = version;
fs.writeFileSync(manifestJsonPath, JSON.stringify(manifestJson, null, 4), 'utf8');
console.log('Updated manifest.json with version:', version);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const outputManifestPath = path.join(outputDir, 'manifest.json');
fs.copyFileSync(manifestJsonPath, outputManifestPath);
console.log('Copied manifest.json to:', outputManifestPath);
});
}
}
const postcssLoader = {
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
require("postcss-url")({
url: "inline",
maxSize: Infinity,
}),
],
},
},
};
const ENVIRONMENT = "production";
module.exports = {
entry: "./src/main.ts",
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
},
{
loader: "webpack-preprocessor-loader",
options: {
params: {
dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif` (multiple lines)
},
directives: {
dev: ENVIRONMENT === "development", // for preprocessor command `#!dev` (single line)
},
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader", postcssLoader],
exclude: /node_modules/,
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader", postcssLoader],
exclude: /node_modules/,
},
{
test: /\.svg$/,
use: "raw-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {
react: path.resolve(__dirname, "node_modules/react"),
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
},
},
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist/circuit-sketcher"),
libraryTarget: "commonjs",
},
target: "node",
//devtool: "inline-source-map",
externals: {
obsidian: "commonjs obsidian",
},
mode: ENVIRONMENT,
plugins: [
new webpack.BannerPlugin({
banner: `/*! Also see LICENSE file in the root of the project. */`,
raw: true,
}),
new UpdateAndCopyManifestPlugin(),
],
};