2023-01-26 16:07:49 +00:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const { ESBuildMinifyPlugin } = require("esbuild-loader");
|
|
|
|
const browserslistToEsbuild = require("browserslist-to-esbuild");
|
2022-10-27 11:49:35 +02:00
|
|
|
|
2023-01-26 16:07:49 +00:00
|
|
|
const packageJson = require("./package.json");
|
2021-08-24 10:36:38 +02:00
|
|
|
|
|
|
|
const nodeModules = [];
|
2023-01-26 16:07:49 +00:00
|
|
|
Object.keys(packageJson.dependencies).forEach((module) => {
|
2021-08-24 10:36:38 +02:00
|
|
|
nodeModules.push(new RegExp(`^${module}(/.+)?$`));
|
|
|
|
});
|
|
|
|
|
2023-01-13 09:31:56 +00:00
|
|
|
/** @type {Omit<import('webpack').Configuration, 'output'>} */
|
|
|
|
const baseConfig = {
|
2021-08-24 10:36:38 +02:00
|
|
|
entry: `${__dirname}/lib/src/index.js`,
|
|
|
|
externals: nodeModules,
|
2021-09-07 14:50:34 +02:00
|
|
|
mode: process.env.NODE_ENV,
|
2023-01-26 16:07:49 +00:00
|
|
|
devtool: process.env.NODE_ENV === "production" ? false : "eval-source-map",
|
2022-10-27 11:49:35 +02:00
|
|
|
optimization: {
|
2023-01-26 16:07:49 +00:00
|
|
|
minimize: process.env.NODE_ENV === "production",
|
2022-10-27 11:49:35 +02:00
|
|
|
minimizer: [
|
|
|
|
new ESBuildMinifyPlugin({
|
2023-01-26 16:07:49 +00:00
|
|
|
target: "es2015",
|
2022-10-27 11:49:35 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2021-08-24 10:36:38 +02:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-10-27 11:49:35 +02:00
|
|
|
test: /\.m?jsx?$/,
|
|
|
|
use: {
|
2023-01-26 16:07:49 +00:00
|
|
|
loader: require.resolve("esbuild-loader"),
|
2022-10-27 11:49:35 +02:00
|
|
|
options: {
|
2023-01-26 16:07:49 +00:00
|
|
|
loader: "jsx",
|
2023-01-06 11:54:09 +00:00
|
|
|
target: browserslistToEsbuild(),
|
2022-10-27 11:49:35 +02:00
|
|
|
},
|
|
|
|
},
|
2021-08-24 10:36:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|svg|jpg|gif)$/,
|
2023-01-26 16:07:49 +00:00
|
|
|
type: "asset",
|
2021-12-14 11:46:47 +01:00
|
|
|
parser: {
|
|
|
|
dataUrlCondition: {
|
|
|
|
maxSize: 8192,
|
|
|
|
},
|
2021-08-24 10:36:38 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
2023-01-26 16:07:49 +00:00
|
|
|
extensions: ["*", ".js"],
|
2021-08-24 10:36:38 +02:00
|
|
|
cacheWithContext: false,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.EnvironmentPlugin({
|
2023-01-26 16:07:49 +00:00
|
|
|
NODE_ENV: "production",
|
2021-08-24 10:36:38 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
2023-01-13 09:31:56 +00:00
|
|
|
|
|
|
|
/** @type {import('webpack').Configuration[]} */
|
|
|
|
const config = [
|
2023-01-13 09:39:49 +00:00
|
|
|
{
|
|
|
|
...baseConfig,
|
|
|
|
output: {
|
|
|
|
path: `${__dirname}/build`,
|
|
|
|
filename: `helper-plugin.${process.env.NODE_ENV}.js`,
|
|
|
|
library: {
|
2023-01-26 16:07:49 +00:00
|
|
|
name: "helperPlugin",
|
|
|
|
type: "umd",
|
2023-01-13 09:39:49 +00:00
|
|
|
},
|
|
|
|
umdNamedDefine: true,
|
|
|
|
},
|
|
|
|
},
|
2023-01-13 09:31:56 +00:00
|
|
|
{
|
|
|
|
...baseConfig,
|
|
|
|
output: {
|
|
|
|
path: `${__dirname}/build`,
|
|
|
|
filename: `helper-plugin.esm.js`,
|
|
|
|
library: {
|
2023-01-26 16:07:49 +00:00
|
|
|
type: "module",
|
2023-01-13 09:31:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
experiments: {
|
|
|
|
outputModule: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...baseConfig,
|
|
|
|
output: {
|
|
|
|
path: `${__dirname}/build`,
|
|
|
|
filename: `helper-plugin.cjs.js`,
|
|
|
|
library: {
|
2023-01-26 16:07:49 +00:00
|
|
|
type: "commonjs",
|
2023-01-13 09:31:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
module.exports = config;
|