forked from NikolayRys/Likely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
73 lines (64 loc) · 2.64 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
/* eslint-env node */
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const pkg = require('./package.json');
const path = require('path');
const license = `Likely $version by Nikolay Rys (linkedin.com/in/nikolay-rys), Ilya Birman (ilyabirman.net), and contributors.
Special thanks to Viktor Karpov (twitter.com/vitkarpov), Ivan Akulov (iamakulov.com), Evgeny Steblinsky (volter9.github.io), and Artem Sapegin (sapegin.me).`;
function getLicenseComment(version) {
return license.replace(/\$version/g, version);
}
module.exports = (env) => {
const isProduction = process.env.NODE_ENV === 'production';
const isDom = env.commonjs !== 'true';
let entry;
let optimization;
const connectingLoader = isDom ? MiniCssExtractPlugin.loader : 'style-loader';
const plugins = [new webpack.BannerPlugin({ banner: getLicenseComment(pkg.version), entryOnly: true })];
if (isProduction) {
optimization = { minimizer: [new TerserPlugin({ extractComments: false })] };
entry = isDom ? { 'likely.min': './source/likely.js' } : { 'likely-commonjs.min': './source/likely-commonjs.js' };
}
else {
entry = isDom ? { likely: './source/likely.js' } : { 'likely-commonjs': './source/likely-commonjs.js' };
}
if (isDom) {
let cssName = 'likely.css';
if (isProduction) {
cssName = 'likely.min.css';
plugins.push(new CssMinimizerPlugin());
}
plugins.push(new MiniCssExtractPlugin({ filename: cssName }));
}
return {
entry,
output: {
filename: '[name].js',
library: {
name: 'likely',
type: 'umd', // https://webpack.js.org/configuration/output/#librarytarget-umd
},
path: path.join(__dirname, '/release'),
globalObject: 'typeof self !== \'undefined\' ? self : this', // https://github.com/webpack/webpack/issues/6784#issuecomment-375941431
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } },
},
{
test: /\.styl$/,
exclude: /node_modules/,
use: [connectingLoader, 'css-loader', 'stylus-loader'],
},
],
},
devtool: 'source-map',
optimization,
plugins,
};
};