-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.ts
199 lines (185 loc) · 5.09 KB
/
webpack.common.ts
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
/**
* Common webpack configuration
*/
import FaviconsWebpackPlugin from 'favicons-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import * as path from 'path'
import VueLoaderPlugin from 'vue-loader/lib/plugin'
import * as webpack from 'webpack'
import Dotenv from 'dotenv-webpack'
const devMode = process.env.NODE_ENV !== 'production'
const fileLoader = {
loader: 'file-loader',
options: {
name: '[path][name].[hash].[ext]',
// outputPath: "/",
},
}
const common: webpack.Configuration = {
entry: './entrypoint.js',
context: path.resolve(__dirname, 'src'),
output: {
filename: 'app.js',
path: path.resolve(__dirname, path.join('dist', 'dev')),
},
resolve: {
extensions: ['.vue', '.mjs', '.js', '.ts', '.tsx', '.json'],
mainFields: ['browser', 'module', 'main'],
alias: {
'@': path.resolve(__dirname, path.join('src')),
'@assets': path.resolve(__dirname, path.join('src', 'assets')),
vue$: 'vue/dist/vue.esm.js', // 'vue/dist/vue.common.js' for webpack 1
},
},
module: {
rules: [
//
// Vue
//
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
},
],
},
//
// Babel
//
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
sourceType: 'unambiguous',
},
},
},
//
// CSS
//
{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
//
// Images
//
// Image optimiser
{
test: /\.(jpg|png|gif|svg)$/i,
loader: 'image-webpack-loader',
// Specify enforce: 'pre' to apply the loader
// before url-loader/svg-url-loader
// and not duplicate it in rules with them
enforce: 'pre',
options: {
bypassOnDebug: true,
},
},
// Loads small images as base64 URIs
// {
// test: /\.(jpe?g|png|gif)$/i,
// loader: "url-loader",
// options: {
// // Images larger than 10 KB won’t be inlined
// limit: 10 * 1024,
// quotes: true,
// },
// },
// Loads small SVG images as base64 URIs (specifically optimised for SVG being text)
// {
// test: /\.svg$/,
// loader: "svg-url-loader",
// options: {
// // Images larger than 10 KB won’t be inlined
// limit: 10 * 1024,
// // Remove quotes around the encoded URL –
// // they’re rarely useful
// noquotes: false,
// },
// },
// Load other SVGs inline
// {
// test: /\.svg$/,
// loader: "svg-inline-loader",
// },
// Load all other images as files
{
test: /\.(png|svg|jpe?g|gif)$/i,
use: [fileLoader],
},
// Load all font files as files
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [fileLoader],
},
],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new webpack.ProgressPlugin(),
new VueLoaderPlugin(),
new Dotenv(),
new HtmlWebpackPlugin({
template: 'index.html',
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
}),
new FaviconsWebpackPlugin({
// Your source logo
logo: path.resolve(__dirname, path.join('src', 'assets', 'logo.png')),
// The prefix for all image files (might be a folder or a name)
prefix: 'icons-[hash]/',
// Emit all stats of the generated icons
emitStats: false,
// The name of the json containing all favicon information
statsFilename: 'iconstats-[hash].json',
// Generate a cache file with control hashes and
// don't rebuild the favicons until those hashes change
persistentCache: true,
// Inject the html into the html-webpack-plugin
inject: true,
// favicon background color (see https://github.com/haydenbleasel/favicons#usage)
background: '#fff',
// favicon app title (see https://github.com/haydenbleasel/favicons#usage)
title: 'Webpack App',
// which icons should be generated (see https://github.com/haydenbleasel/favicons#usage)
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
opengraph: false,
twitter: false,
yandex: false,
windows: false,
},
}),
],
externals: {
jquery: '$',
},
}
export default common