-
Notifications
You must be signed in to change notification settings - Fork 109
/
webpack.config.js
88 lines (79 loc) · 2.13 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
var webpack = require('webpack');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var createVariants = require('parallel-webpack').createVariants;
// Import the plugin:
var argv = require('yargs').argv.env;
var env = argv.mode;
console.warn(env);
var libraryName = 'across-tabs';
var libVersion = JSON.stringify(require('./package.json').version);
var libraryHeaderComment =
'\n' +
'across-tabs ' +
libVersion +
'\n' +
'https://github.com/wingify/across-tabs\n' +
'MIT licensed\n' +
'\n' +
'Copyright (C) 2017-2023 Wingify Pvt. Ltd. - Authored by Varun Malhotra(https://github.com/softvar)\n';
var plugins = [
new webpack.BannerPlugin({
banner: libraryHeaderComment,
entryOnly: true
})
];
if (env === 'build') {
plugins.push(new UglifyJsPlugin({ minimize: true }));
}
function createConfig(options) {
return {
entry: __dirname + '/src/index.js',
devtool: 'source-map',
output: {
path: __dirname + '/dist',
library: 'AcrossTabs',
filename: libraryName + (options.target ? '.' + options.target : '') + (env === 'build' ? '.min.js' : '.js'),
libraryTarget: options.target || 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /(\.js)$/,
exclude: /(node_modules|bower_components)/,
use: {
// babel-loader to convert ES6 code to ES5 + amdCleaning requirejs code into simple JS code, taking care of modules to load as desired
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: []
}
}
},
{
enforce: 'pre',
test: /(\.js)$/,
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
fix: true,
emitError: true,
emitWarning: true,
failOnWarning: env === 'build',
failOnError: env === 'build'
}
}
}
]
},
plugins: plugins
};
}
// At the end of the file:
module.exports = createVariants(
{
target: ['this', '']
},
createConfig
);