forked from Danziger/slotjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
143 lines (128 loc) · 4.59 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
135
136
137
138
139
140
141
142
143
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const pkg = require('./package.json');
module.exports = (env, argv) => {
const DEV = argv.mode === 'development';
const PROD = argv.mode === 'production';
const config = {
devtool: DEV ? 'eval-source-map' : false,
entry: {
main: [
'./src/app/main.js',
'./src/app/main.scss',
],
},
/*
// TODO: Integrate with ESLint:
// https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/1321
resolve: {
alias: {
common: path.resolve(__dirname, 'src/common/'),
},
},
*/
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: './',
},
devServer: {
contentBase: path.resolve(__dirname, 'static'),
publicPath: '/slotjs/',
},
module: {
rules: [{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
fix: true,
},
},
}, {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
}, {
test: /\.scss/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
}],
},
plugins: [
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'dist/index.html'),
template: path.resolve(__dirname, 'src/app/templates/index.html'),
title: 'SlotJS / Circular slot machine built with JavaScript & Emojis!',
description: pkg.description,
favicon: path.resolve(__dirname, 'static/favicon.ico'),
inlineSource: '.(js|css)$', // Inline JS and CSS.
minify: PROD,
meta: {
author: pkg.author.name,
description: pkg.description,
viewport: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no',
},
// We can use templateParameters if more options are required, but it will override all the above.
}),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new StyleLintPlugin({
syntax: 'scss',
fix: true,
}),
new CopyWebpackPlugin([{
from: 'static',
}]),
new webpack.DefinePlugin({
'process.env': {
DEVELOPMENT: true,
},
}),
// new BundleAnalyzerPlugin(),
],
optimization: {
// Extract all styles in a single file:
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
},
minimizer: PROD ? [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false,
}),
// Might not be needed with Webpack 5:
new OptimizeCSSAssetsPlugin({}),
] : [],
},
};
if (PROD) {
config.plugins.push(new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin));
}
return config;
};