-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·180 lines (172 loc) · 4.81 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
/**
* Assets Config file
*/
const serverConfiguration = {
internal: {
server: {
baseDir: 'dist',
},
port: 3000,
},
external: {
proxy: 'http://localhost:3000/',
},
};
const path = require('path');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ImageMinPlugin = require('imagemin-webpack-plugin').default;
let targetServerConfiguration = serverConfiguration.internal;
const config = function(env, args) {
const hasSourceMaps = process.env.NODE_ENV !== "production";
const terserOptions = process.env.NODE_ENV === "production" ? {
extractComments: "all",
compress: {
drop_console: true
}
} : {};
if (args.externalServer !== undefined && args.externalServer) {
targetServerConfiguration = serverConfiguration.external;
}
return {
entry: {
app: './src/js/app.js',
},
output: {
filename: 'js/[name].js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
alias: {
config: path.resolve(__dirname, "src/js/config/config.".concat((process.env.ISMOBILE) ? "mobile.js" : (process.env.NODE_ENV === "production") ? "prod.js" : "dev.js"))
}
},
module: {
rules: [
{
test: /\.scss$/,
use: ['style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /\.(png|gif|jpg|jpeg)$/,
use: [
{
loader: 'url-loader',
options: { name: 'images/design/[name].[hash:6].[ext]', publicPath: '../', limit: 8192 },
},
],
},
{
test: /\.(eot|ttf|woff|woff2)$/,
use: [
{
loader: 'url-loader',
options: { name: 'fonts/[name].[hash:6].[ext]', publicPath: '../', limit: 8192 },
},
],
},
{
test: /\.abc$/i,
use: [
{
loader: 'raw-loader',
options: {
esModule: false
}
}
]
},
{
test: /\.svg/,
use: {
loader: "svg-url-loader",
options: {},
},
}
],
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
sourceMap: hasSourceMaps,
terserOptions,
}),
//new OptimizeCssAssetsPlugin({}),//stopped working
new CssMinimizerPlugin(),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
plugins: [
new BrowserSyncPlugin({
...targetServerConfiguration,
files: ['src/*'],
ghostMode: {
clicks: false,
location: false,
forms: false,
scroll: false,
},
injectChanges: true,
logFileChanges: true,
logLevel: 'debug',
logPrefix: 'wepback',
notify: true,
reloadDelay: 0,
}),
new HtmlWebpackPlugin({
inject: true,
hash: false,
filename: 'index.html',
template: path.resolve(__dirname, 'src', 'index.html'),
favicon: path.resolve(__dirname, 'src', 'images', 'favicon.ico'),
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
}),
new ImageMinPlugin({ test: /\.(jpg|jpeg|png|gif|svg)$/i }),
new CleanWebpackPlugin({
/**
* Some plugins used do not correctly save to webpack's asset list.
* Disable automatic asset cleaning until resolved
*/
cleanStaleWebpackAssets: false,
verbose: true,
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'src', 'images', 'content'),
to: path.resolve(__dirname, 'dist', 'images', 'content'),
toType: 'dir',
},
{
from: path.resolve(__dirname, 'src', 'fonts', 'midi-js-soundfonts'),
to: path.resolve(__dirname, 'dist', 'midi-js-soundfonts'),
toType: 'dir',
},
],
}),
],
devtool: hasSourceMaps && "inline-source-map"
};
};
module.exports = config;