-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.cjs-unused
106 lines (95 loc) · 1.97 KB
/
webpack.config.cjs-unused
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
// Author: Axel Antoine
// mail: [email protected]
// website: https://axantoine.com
// 2022/03/03
// Loki, Inria project-team with Université de Lille
// within the Joint Research Unit UMR 9189 CNRS-Centrale
// Lille-Université de Lille, CRIStAL.
// https://loki.lille.inria.fr
// LICENCE: Licence.md
const pkg = require('./package.json');
const webpack = require('webpack');
const {merge} = require('webpack-merge');
const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const nodeExternals = require('webpack-node-externals');
const libConfig = {
target: "web",
entry: ["./src/index.ts"],
devtool: "source-map",
mode: "production",
externalsPresets: {node: true},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
}
]
},
resolve: {
extensions: ['.ts'],
},
};
const esmConfig = {
name: "esm",
experiments: {
outputModule: true,
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "build"),
library: {
type: "module",
}
}
};
const cjsConfig = {
name: "cjs",
output: {
filename: "index.cjs",
path: path.resolve(__dirname, "build"),
library: {
type: "commonjs",
},
},
};
const demoConfig = {
name: "demo",
target: "web",
mode: "development",
entry: ["./demo/intersect.ts"],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
configFile: "tsconfig-demo.json"
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "demo/index.html")
})
],
resolve: {
extensions: ['.ts'],
},
output: {
filename: "intersect.js",
path: path.resolve(__dirname, "build/demo"),
},
}
module.exports = env => {
esm = merge(esmConfig, libConfig)
cjs = merge(cjsConfig, libConfig)
if (env.demo) {
return [demoConfig];
} else {
return [esm, cjs];
}
}