forked from lab-cosmo/chemiscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
58 lines (53 loc) · 1.89 KB
/
webpack.config.ts
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
import path from 'path';
import * as webpack from 'webpack';
import { execSync } from 'child_process';
const GIT_VERSION = execSync('git describe --tags --dirty').toString().trim();
export const BASE_CONFIG: webpack.Configuration = {
plugins: [
new webpack.DefinePlugin({
CHEMISCOPE_GIT_VERSION: `"${GIT_VERSION}"`,
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
extensions: ['.js', '.ts'],
modules: ['./node_modules'],
},
module: {
rules: [
{ test: /\.ts?$/, use: ['ts-loader', './utils/webpack-assert-message.ts'] },
{ test: /\.css?$/, use: ['style-loader', 'css-loader'] },
{ test: /\.html?$/, loader: 'html-loader', options: { minimize: true } },
{ test: /\.svg?$/, loader: 'html-loader', options: { minimize: true } },
// this is required by plotly, since we are building our own bundle
{ test: /\.js?$/, use: ['ify-loader'] },
],
},
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ConfigFn = (env: unknown, argv: any) => webpack.Configuration;
const config: ConfigFn = (env, argv) => {
if (!('mode' in argv)) {
throw Error('please specify the build mode');
}
return {
...BASE_CONFIG,
target: 'web',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
devtool: argv.mode === 'development' ? 'inline-source-map' : undefined,
entry: {
chemiscope: './src/index.ts',
'chemiscope-app': './app/app.ts',
'molecule-viewer': './src/structure/widget.ts',
},
output: {
filename: '[name].min.js',
library: 'Chemiscope',
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
},
};
};
export default config;