-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.common.cjs
86 lines (80 loc) · 3.12 KB
/
webpack.common.cjs
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
/* eslint-env node */
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const PACKAGE = require('./package.json');
const srcPath = path.resolve(__dirname, 'esm');
const outputPath = path.resolve(__dirname, 'dist');
const OUTPUT_FILENAMES = {
// For legacy reasons, the filenames that people expect are different than the "library" name
LocusZoom: 'locuszoom.app.min.js',
LzDynamicUrls: 'ext/lz-dynamic-urls.min.js',
LzWidgetAddons: 'ext/lz-widget-addons.min.js',
LzForestTrack: 'ext/lz-forest-track.min.js',
LzIntervalsTrack: 'ext/lz-intervals-track.min.js',
LzIntervalsEnrichment: 'ext/lz-intervals-enrichment.min.js',
LzCredibleSets: 'ext/lz-credible-sets.min.js',
LzParsers: 'ext/lz-parsers.min.js',
LzTabix: 'ext/lz-tabix-source.min.js',
LzAggregationTests: 'ext/lz-aggregation-tests.min.js',
};
module.exports = {
context: __dirname,
entry: {
// When a <script> is included in the page, entrypoint name = variable with content
LocusZoom: path.resolve(srcPath, 'index.js'),
LzDynamicUrls: path.resolve(srcPath, 'ext', 'lz-dynamic-urls.js'),
LzWidgetAddons: path.resolve(srcPath, 'ext', 'lz-widget-addons.js'),
LzForestTrack: path.resolve(srcPath, 'ext', 'lz-forest-track.js'),
LzIntervalsTrack: path.resolve(srcPath, 'ext', 'lz-intervals-track.js'),
LzIntervalsEnrichment: path.resolve(srcPath, 'ext', 'lz-intervals-enrichment.js'),
LzCredibleSets: path.resolve(srcPath, 'ext', 'lz-credible-sets.js'),
LzParsers: path.resolve(srcPath, 'ext', 'lz-parsers/index.js'),
LzTabix: path.resolve(srcPath, 'ext', 'lz-tabix-source.js'),
LzAggregationTests: path.resolve(srcPath, 'ext', 'lz-aggregation-tests.js'),
},
plugins: [
new CleanWebpackPlugin({
// To simplify tooling, we will assume that (S)CSS changes rarely, and build it outside of webpack
cleanOnceBeforeBuildPatterns: ['**/*', '!locuszoom.css*'],
}),
new webpack.BannerPlugin(`Locuszoom ${PACKAGE.version}`), // add after uglify step
new ESLintPlugin(),
],
resolve: {
symlinks: false,
modules: [
'node_modules',
],
},
module: {
rules: [
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
],
},
output: {
path: outputPath,
filename: (data) => {
// For backwards compatibility, the filename is different than the chunk name.
const match = OUTPUT_FILENAMES[data.chunk.name];
if (!match) {
const msg = `Must provide a filename for this chunk: ${data.chunk.name}`;
console.error(msg);
throw new Error(msg);
}
return match;
},
library: '[name]',
libraryExport: 'default',
},
externals: {
d3: 'd3',
locuszoom: 'LocusZoom',
'raremetal.js': 'raremetal',
},
};