-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
webpack.config.js
85 lines (76 loc) · 2.22 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
const webpack = require('webpack');
const path = require('path');
const dev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const NAME = 'air-datepicker';
// Plugins
// -------------------------------------------------
let plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV).toLowerCase()
}
}),
new HtmlWebpackPlugin({
template: './index-dev.html'
}),
];
let buildPlugins = [
new MiniCssExtractPlugin({
filename: `${NAME}.css`,
}),
];
// Entry
// -------------------------------------------------
let entry = {
index: './index-dev.js',
};
if (!dev) {
entry.index = './src/datepicker.js';
}
// Config
// -------------------------------------------------
let config = {
mode: dev ? 'development' : 'production',
entry: entry,
devtool: dev ? 'eval-source-map' : false,
output: {
path: path.resolve(__dirname, 'dist'),
filename: dev ? 'js/[name].js' : `${NAME}.js`,
publicPath: '/',
chunkFilename: 'js/[name].js',
library: dev ? undefined : 'AirDatepicker',
libraryTarget: dev ? undefined : 'umd',
libraryExport: dev ? undefined : 'default',
globalObject: 'this',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)|dist/,
use: ['babel-loader']
},
{
test: /\.scss$/,
use: [
dev ? 'style-loader' : MiniCssExtractPlugin.loader,
{loader: 'css-loader', options: {sourceMap: dev}},
{loader:'postcss-loader', options: {sourceMap: dev}},
{loader: 'sass-loader', options: {sourceMap: dev}},
]
},
]
},
resolve: {
modules: [`${__dirname}/src/js`, `${__dirname}/src`, `${__dirname}/dist`, 'node_modules']
},
plugins: dev ? plugins : buildPlugins,
};
if (dev) {
config.devServer = {
hot: true
};
}
module.exports = config;