forked from ashleydw/lightbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
89 lines (83 loc) · 2.43 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
'use strict';
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production'
function getHotCSS(bundle, devMode) {
if(!devMode) {
return bundle;
}
return [
'css-hot-loader',
].concat(bundle);
}
const prod = {
mode: devMode ? 'development' : 'production',
devtool: devMode ? 'cheap-module-source-map' : 'source-map',
entry: [
'./ekko-lightbox.js',
'./ekko-lightbox.less'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: devMode ? '[name].js' : 'ekko-lightbox.js'
},
module: {
rules: [{
test: /\.less$/,
use: getHotCSS([
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { sourceMap: true } },
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
sourceMap: true,
plugins: (loader) => [
require('autoprefixer')({
browsers: ['last 2 versions']
}),
require('cssnano')()
]
}
},
{ loader: 'less-loader', options: { sourceMap: true } }
], devMode)
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [require('babel-preset-env')]
}
}
}]
},
plugins: [
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : 'ekko-lightbox.css'
})
],
};
if (!devMode) {
prod.plugins.push(
new webpack.BannerPlugin({
banner:
'Lightbox for Bootstrap by @ashleydw\n' +
'https://github.com/ashleydw/lightbox\n' +
'\n' +
'License: https://github.com/ashleydw/lightbox/blob/master/LICENSE\n',
entryOnly: true,
include: 'ekko-lightbox.js'
})
);
} else {
prod.entry.push('./index.html');
prod.module.rules.push({
test: /\.html$/,
use: "raw-loader"
});
}
module.exports = prod;