webpack.plugin.js
1.2 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
const CopyPlugin = require("copy-webpack-plugin");
const { merge } = require("webpack-merge");
const prodConfig = require("./webpack.prod");
const WebpackBar = require("webpackbar");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const path = require("path");
const fs = require("fs");
const { cwd } = require("process");
delete prodConfig.plugins;
const extensions = ["ts", "tsx"];
let extension;
extensions.forEach((i) => {
if (fs.existsSync(path.resolve(cwd(), `index.${i}`))) {
extension = i;
}
});
const name = cwd().split("/").reverse()[0];
module.exports = merge(prodConfig, {
output: {
filename: `../../../dist/${name}/index.js`,
libraryTarget: "system",
},
entry: path.resolve(cwd(), `./index.${extension}`),
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(cwd(), '../../plugin.json'),
to: path.resolve(cwd(), '../../dist/plugin.json'),
},
],
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(cwd(), '../../static'),
to: path.resolve(cwd(), '../../dist/static'),
},
],
}),
new WebpackBar(),
new NodePolyfillPlugin(),
],
});