|
1 | 1 | const path = require("path"); |
2 | 2 | const webpack = require("webpack"); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +class UpdateAndCopyManifestPlugin { |
| 6 | + apply(compiler) { |
| 7 | + compiler.hooks.afterEmit.tap('UpdateAndCopyManifestPlugin', (compilation) => { |
| 8 | + const packageJsonPath = path.resolve(__dirname, 'package.json'); |
| 9 | + const manifestJsonPath = path.resolve(__dirname, 'manifest.json'); |
| 10 | + const outputDir = path.resolve(__dirname, 'dist', 'circuit-sketcher'); |
| 11 | + |
| 12 | + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 13 | + const version = packageJson.version; |
| 14 | + |
| 15 | + const manifestJson = JSON.parse(fs.readFileSync(manifestJsonPath, 'utf8')); |
| 16 | + manifestJson.version = version; |
| 17 | + |
| 18 | + fs.writeFileSync(manifestJsonPath, JSON.stringify(manifestJson, null, 4), 'utf8'); |
| 19 | + |
| 20 | + console.log('Updated manifest.json with version:', version); |
| 21 | + |
| 22 | + if (!fs.existsSync(outputDir)) { |
| 23 | + fs.mkdirSync(outputDir, { recursive: true }); |
| 24 | + } |
| 25 | + |
| 26 | + const outputManifestPath = path.join(outputDir, 'manifest.json'); |
| 27 | + fs.copyFileSync(manifestJsonPath, outputManifestPath); |
| 28 | + |
| 29 | + console.log('Copied manifest.json to:', outputManifestPath); |
| 30 | + }); |
| 31 | + } |
| 32 | +} |
3 | 33 |
|
4 | 34 | const postcssLoader = { |
5 | | - loader: "postcss-loader", |
6 | | - options: { |
7 | | - postcssOptions: { |
8 | | - plugins: [ |
9 | | - require("postcss-url")({ |
10 | | - url: "inline", |
11 | | - maxSize: Infinity, |
12 | | - }), |
13 | | - ], |
| 35 | + loader: "postcss-loader", |
| 36 | + options: { |
| 37 | + postcssOptions: { |
| 38 | + plugins: [ |
| 39 | + require("postcss-url")({ |
| 40 | + url: "inline", |
| 41 | + maxSize: Infinity, |
| 42 | + }), |
| 43 | + ], |
| 44 | + }, |
14 | 45 | }, |
15 | | - }, |
16 | 46 | }; |
17 | 47 |
|
18 | 48 | const ENVIRONMENT = "production"; |
19 | 49 |
|
20 | 50 | module.exports = { |
21 | | - entry: "./src/main.ts", |
22 | | - module: { |
23 | | - rules: [ |
24 | | - { |
25 | | - test: /\.tsx?$/, |
26 | | - use: [ |
27 | | - { |
28 | | - loader: "ts-loader", |
29 | | - }, |
30 | | - { |
31 | | - loader: "webpack-preprocessor-loader", |
32 | | - options: { |
33 | | - params: { |
34 | | - dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif` (multiple lines) |
35 | | - }, |
36 | | - directives: { |
37 | | - dev: ENVIRONMENT === "development", // for preprocessor command `#!dev` (single line) |
38 | | - }, |
| 51 | + entry: "./src/main.ts", |
| 52 | + module: { |
| 53 | + rules: [ |
| 54 | + { |
| 55 | + test: /\.tsx?$/, |
| 56 | + use: [ |
| 57 | + { |
| 58 | + loader: "ts-loader", |
| 59 | + }, |
| 60 | + { |
| 61 | + loader: "webpack-preprocessor-loader", |
| 62 | + options: { |
| 63 | + params: { |
| 64 | + dev: ENVIRONMENT === "development", // for preprocessor commands defined with `#!if dev` and `#!endif` (multiple lines) |
| 65 | + }, |
| 66 | + directives: { |
| 67 | + dev: ENVIRONMENT === "development", // for preprocessor command `#!dev` (single line) |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + ], |
| 72 | + exclude: /node_modules/, |
| 73 | + }, |
| 74 | + { |
| 75 | + test: /\.css$/, |
| 76 | + use: ["style-loader", "css-loader", postcssLoader], |
| 77 | + exclude: /node_modules/, |
| 78 | + }, |
| 79 | + { |
| 80 | + test: /\.scss$/, |
| 81 | + use: ["style-loader", "css-loader", "sass-loader", postcssLoader], |
| 82 | + exclude: /node_modules/, |
| 83 | + }, |
| 84 | + { |
| 85 | + test: /\.svg$/, |
| 86 | + use: "raw-loader", |
| 87 | + exclude: /node_modules/, |
39 | 88 | }, |
40 | | - }, |
41 | 89 | ], |
42 | | - exclude: /node_modules/, |
43 | | - }, |
44 | | - { |
45 | | - test: /\.css$/, |
46 | | - use: ["style-loader", "css-loader", postcssLoader], |
47 | | - exclude: /node_modules/, |
48 | | - }, |
49 | | - { |
50 | | - test: /\.scss$/, |
51 | | - use: ["style-loader", "css-loader", "sass-loader", postcssLoader], |
52 | | - exclude: /node_modules/, |
53 | | - }, |
54 | | - { |
55 | | - test: /\.svg$/, |
56 | | - use: "raw-loader", |
57 | | - exclude: /node_modules/, |
58 | | - }, |
59 | | - ], |
60 | | - }, |
61 | | - resolve: { |
62 | | - extensions: [".ts", ".tsx", ".js"], |
63 | | - alias: { |
64 | | - react: path.resolve(__dirname, "node_modules/react"), |
65 | | - "react-dom": path.resolve(__dirname, "node_modules/react-dom"), |
66 | 90 | }, |
67 | | - }, |
68 | | - output: { |
69 | | - filename: "main.js", |
70 | | - path: path.resolve(__dirname, "dist/circuit-sketcher"), |
71 | | - libraryTarget: "commonjs", |
72 | | - }, |
73 | | - target: "node", |
74 | | - //devtool: "inline-source-map", |
75 | | - externals: { |
76 | | - obsidian: "commonjs obsidian", |
77 | | - }, |
78 | | - mode: ENVIRONMENT, |
79 | | - plugins: [ |
80 | | - new webpack.BannerPlugin({ |
81 | | - banner: `/*! Also see LICENSE file in the root of the project. */`, |
82 | | - raw: true, |
83 | | - }), |
84 | | - ], |
| 91 | + resolve: { |
| 92 | + extensions: [".ts", ".tsx", ".js"], |
| 93 | + alias: { |
| 94 | + react: path.resolve(__dirname, "node_modules/react"), |
| 95 | + "react-dom": path.resolve(__dirname, "node_modules/react-dom"), |
| 96 | + }, |
| 97 | + }, |
| 98 | + output: { |
| 99 | + filename: "main.js", |
| 100 | + path: path.resolve(__dirname, "dist/circuit-sketcher"), |
| 101 | + libraryTarget: "commonjs", |
| 102 | + }, |
| 103 | + target: "node", |
| 104 | + //devtool: "inline-source-map", |
| 105 | + externals: { |
| 106 | + obsidian: "commonjs obsidian", |
| 107 | + }, |
| 108 | + mode: ENVIRONMENT, |
| 109 | + plugins: [ |
| 110 | + new webpack.BannerPlugin({ |
| 111 | + banner: `/*! Also see LICENSE file in the root of the project. */`, |
| 112 | + raw: true, |
| 113 | + }), |
| 114 | + new UpdateAndCopyManifestPlugin(), |
| 115 | + ], |
85 | 116 | }; |
0 commit comments