forked from blurymind/YarnClassic
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
executable file
·209 lines (205 loc) · 5.75 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
const path = require('path');
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin');
const CssUrlRelativePlugin = require('css-url-relative-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const WorkboxPlugin = require('workbox-webpack-plugin');
const IS_DEV = process.env.NODE_ENV === 'dev';
const config = {
mode: IS_DEV ? 'development' : 'production',
devtool: IS_DEV ? 'eval' : 'source-map',
entry: path.resolve(__dirname, 'src', 'js', 'index.js'),
output: {
filename: 'js/[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
},
node: {
fs: 'empty',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(css|scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: IS_DEV,
},
},
'css-loader',
'sass-loader',
],
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 1024,
name: '[name].[ext]',
fallback: 'file-loader',
outputPath: 'public/images',
},
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65,
},
pngquant: {
quality: '65-90',
speed: 4,
},
gifsicle: {
interlaced: false,
},
webp: {
quality: 75,
},
},
},
],
},
{
test: /\.(ttf|eot|woff|woff2|ico)$/,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'windows.jQuery': 'jquery',
Util: 'exports-loader?Util!bootstrap/js/dist/util',
ko: 'exports-loader?!knockout',
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'src', 'public'),
to: 'public',
},
]),
new MiniCssExtractPlugin({
filename: IS_DEV ? 'css/[name].css' : 'css/[name].[contenthash].css',
chunkFilename: 'css/[id].css',
}),
new webpack.HashedModuleIdsPlugin(),
new PreloadWebpackPlugin({
include: 'initial',
}),
new CssUrlRelativePlugin(),
new WebpackPwaManifest({
filename: 'manifest.json',
// start_url: 'YarnEditor/.',
inject: true,
fingerprints: false,
name: 'Crochet',
short_name: 'Crochet',
description: 'An editor for Yarn files.',
background_color: '#3367D6',
theme_color: '#3367D6',
display: 'fullscreen',
crossorigin: 'use-credentials', //can be null, use-credentials or anonymous
icons: [
{
src: path.resolve('src/public/icon.png'),
sizes: [96, 128, 192, 512], // multiple sizes, 192 needed by pwa
},
{
src: path.resolve('src/public/icon.ico'),
sizes: [32], // you can also use the specifications pattern
},
],
share_target: {
// action: 'share-target',
// enctype: 'multipart/form-data',
// method: 'POST', //github.io does not allow post
// params: {
// files: [{
// name: 'image',
// accept: ['image/*']
// }]
// }
action: '/YarnEditor/',
method: 'GET',
enctype: 'application/x-www-form-urlencoded',
params: {
title: 'title',
text: 'text',
url: 'url',
}
},
}),
new HtmlWebPackPlugin({
template: path.resolve(__dirname, './src/index.html'),
favicon: path.resolve('src/public/icon.ico'),
minify: {
collapseWhitespace: true,
removeComments: false, // This is mandatory, due to knockout's virtual bindings
useShortDoctype: true,
},
}),
// new WorkboxPlugin.GenerateSW({
// swDest: path.resolve(__dirname, 'dist', 'sw.js'),
// exclude: [/\.map$/, /_redirects/],
// runtimeCaching: [{
// urlPattern: /https:\/\/yarnspinnertool\.github\.io\/YarnEditor\//,
// handler: 'NetworkFirst' //CacheFirst
// }],
// }),
new WorkboxPlugin.InjectManifest({
swDest: path.resolve(__dirname, 'dist', 'sw.js'),
exclude: [/\.map$/, /_redirects/],
swSrc : path.resolve(__dirname, 'src', 'sw-src.js'),
})
],
devServer: {
contentBase: path.join(__dirname, 'src'),
watchContentBase: true,
host: '0.0.0.0', //this will allow you to run it on a smartphone with 8080 port. Use ipconfig or ifconfig to see broadcast address
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true,
},
},
},
minimizer: [],
},
};
if (!IS_DEV) {
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
config.optimization.minimizer.push(
new TerserPlugin(),
new OptimizeCSSAssetsPlugin({})
);
}
module.exports = config;