diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-04 12:20:46 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-04 12:20:46 +0530 |
| commit | a08607762db5681785159358084213558a5f11f9 (patch) | |
| tree | f3a6245c685ca942ce5fcf918e116509506b7c5a /webpack.config.js | |
| download | banglar-bhumi-utils-a08607762db5681785159358084213558a5f11f9.tar.gz banglar-bhumi-utils-a08607762db5681785159358084213558a5f11f9.zip | |
Initial commit
Diffstat (limited to 'webpack.config.js')
| -rw-r--r-- | webpack.config.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..d98d83f --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,52 @@ +const fs = require("fs"); +const path = require("path"); +const CopyPlugin = require("copy-webpack-plugin"); +const manifest = require("./static/manifest.json"); + +const SOURCE_DIR = path.resolve(__dirname, "src"); +const STATIC_DIR = path.resolve(__dirname, "static"); + +const generateScriptBuildConfig = script => { + const scriptName = script.substring(0, script.length - 3); + let entry = path.resolve(SOURCE_DIR, `scripts/${scriptName}.ts`); + if (!fs.existsSync(entry)) { + entry = path.resolve(SOURCE_DIR, `scripts/${scriptName}/index.ts`); + } + + return { + entry, + mode: "production", + output: { + filename: `${scriptName}.js` + }, + resolve: { + extensions: ["", ".ts", ".js", ".sjs"], + alias: { + "@": SOURCE_DIR + } + }, + module: { + rules: [ + { test: /\.sjs$/, loader: "raw-loader" }, + { test: /\.tsx?$/, loader: "ts-loader" } + ] + } + }; +}; + +let scripts = []; + +for (const script of manifest.content_scripts) { + scripts = scripts.concat(script.js.map(generateScriptBuildConfig)); +} + +scripts[scripts.length - 1].plugins = (scripts[scripts.length - 1].plugins || []).concat([ + new CopyPlugin({ + patterns: [{ + from: STATIC_DIR, + to: "./" + }] + }) +]); + +module.exports = scripts; |
