-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
134 lines (127 loc) · 3.07 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const dotenv = require('dotenv');
// set dotenv
dotenv.config();
const config = (env, options) => {
const dev = options.mode === 'development';
// base
let out = {
name: 'EasyLogicColorPicker',
mode: dev ? 'development' : 'production',
resolve: {
extensions: [ '.js' ],
alias: {
'~': path.resolve(__dirname, './src'),
},
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
{
test: /\.(jpg|png|gif|svg)$/,
loader: 'file-loader',
options: {
publicPath: './',
name: '[name].[ext]',
limit: 10000,
},
},
],
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].css' }),
],
};
/**
* Development
*/
if (dev) {
out.entry = {
app: './public/index.js',
};
out.output = {
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].js',
};
out.devtool = 'inline-source-map';
out.devServer = {
hot: true,
host: process.env.HOST ? process.env.HOST : '0.0.0.0',
port: process.env.PORT ? Number(process.env.PORT) : (options.port || 3000),
historyApiFallback: true,
open: process.env.OPEN_BROWSER === 'true',
};
out.module.rules.push({
test: /\.html$/,
use: [
{
loader: "html-loader",
options: { minimize: false }
}
]
});
out.plugins.push(
new HtmlWebpackPlugin({ template: './public/index.html' })
);
out.plugins.push(
new webpack.DefinePlugin({
ROUTE: JSON.stringify(process.env.ROUTE),
})
);
}
/**
* Production
*/
if (!dev) {
out.entry = {
'EasyLogicColorPicker': './src/index.js',
};
out.output = {
path: __dirname + '/dist',
filename: '[name].js',
publicPath: './',
library: '[name]',
libraryTarget: 'umd',
libraryExport: 'default'
};
out.optimization = {
minimize: true,
minimizer: [
new TerserJSPlugin({
minify: (file, sourceMap) => {
const uglifyJsOptions = {};
if (sourceMap) {
uglifyJsOptions.sourceMap = { content: sourceMap };
}
let str = require('uglify-js').minify(file, uglifyJsOptions);
str.code = str.code.replace(/\s\s/gi, '');
return str;
},
}),
new CssMinimizerPlugin(),
],
};
}
return out;
};
module.exports = config;