This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
94 lines (85 loc) · 2.11 KB
/
webpack.config.js
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
const webpack = require('webpack');
const path = require('path');
const fs = require('fs-extra');
const exec = require('child_process').execSync;
const Dotenv = require('dotenv-webpack');
const nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const merge = require('webpack-merge');
const version = exec('git describe --exact-match --tag HEAD 2>/dev/null || git rev-parse --short HEAD').toString().trim();
const license = fs.readFileSync('LICENSE', 'ascii');
if (!fs.existsSync('.env')) {
fs.copySync('.env.example', '.env');
console.log('Copied .env.example => .env');
}
const licenseBanner = new webpack.BannerPlugin(license + '\nhash:[hash], chunkhash:[chunkhash], name:[name], version:' + version);
const common = {
mode: 'none',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
library: 'maps4news',
},
module: {
rules: [
{
test: /\.js$/,
include: /(src)/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
optimization: {
concatenateModules: true,
minimize: true,
minimizer: [new TerserPlugin({
test: /\.min\.js(\?.*)?$/i,
})],
occurrenceOrder: true,
},
node: false,
devtool: 'source-map',
plugins: [
new Dotenv({
safe: true,
systemvars: true,
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
}),
],
};
module.exports = [
// Browser
merge(common, {
target: 'web',
output: {
libraryTarget: 'umd',
},
externals: [],
entry: {
'bundle.browser': './src/index.js',
'bundle.browser.min': './src/index.js',
},
plugins: [
new webpack.BannerPlugin('This bundle contains the following packages:\n' + exec('$(npm bin)/licensecheck')),
licenseBanner,
],
}),
// Node
merge(common, {
target: 'node',
output: {
libraryTarget: 'commonjs2',
},
externals: [nodeExternals()],
entry: {
'bundle': './src/index.js',
'bundle.min': './src/index.js',
},
plugins: [
licenseBanner,
],
}),
];