This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
70 lines (67 loc) · 1.99 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
const { join } = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
const site = join(__dirname, 'site')
const cssProcessorOptions = { discardComments: { removeAll: true } }
const cssLoaderOptions = { importLoaders: isProduction ? 1 : 0 }
module.exports = (env = {}) => ({
mode: isProduction ? 'production' : 'development',
entry: join(site, 'main.js'),
output: {
path: join(site, 'dist'),
filename: 'js/[name].[chunkhash].js'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': site
}
},
plugins: [
...(env.singleRun ? [
new CleanWebpackPlugin()
] : []),
new HtmlWebpackPlugin({ template: './site/index.html' }),
new VueLoaderPlugin(),
...(isProduction ? [
new OptimizeCssAssetsPlugin({ cssProcessorOptions }),
new MiniCssExtractPlugin({ filename: 'css/[name].[hash].css' })
] : [])
],
module: {
rules: [
{ test: /\.js$/, include: site, loader: 'babel-loader' },
{ test: /\.vue$/, include: site, loader: 'vue-loader' },
{
test: /\.css$/,
include: site,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
{ loader: 'css-loader', options: cssLoaderOptions },
...(isProduction ? [
{
loader: '@fullhuman/purgecss-loader',
options: { content: [join(site, 'App.vue')] }
}
] : [])
]
},
{
test: /\.html$/,
resourceQuery: /^\?vue/,
include: site,
loader: '@ianwalter/prism-loader'
}
]
},
devServer: {
allowedHosts: [
'.glitch.me',
'.ianwalter.dev'
]
}
})