-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
67 lines (63 loc) · 1.52 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
const path = require('path'),
webpack = require('webpack'),
package = require('./package.json'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'),
buildMode = 'production'; // 'development' or 'production'
module.exports = {
mode: buildMode,
entry: {
kamadatepicker: ['./src/kamadatepicker.js'],
},
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: getPlugins(),
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: buildMode === 'development',
},
},
'css-loader',
'sass-loader',
],
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env'],
},
},
},
],
},
};
function getPlugins() {
let plugins = [
new MiniCssExtractPlugin({ filename: 'kamadatepicker.min.css' }),
];
if (buildMode === 'production') {
plugins.push(
new webpack.BannerPlugin(`${package.name} - version ${package.version}`)
);
plugins.push(new OptimizeCssAssetsPlugin());
} else if (buildMode === 'development') {
plugins.push(
new webpack.BannerPlugin({
banner: '/* @ sourceURL=[name].js */',
raw: true,
})
);
}
return plugins;
}