-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
154 lines (151 loc) · 4.4 KB
/
webpack.config.js
File metadata and controls
154 lines (151 loc) · 4.4 KB
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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
// Cleans dist folder before building for fresh build
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const PurgecssPlugin = require('purgecss-webpack-plugin')
const WebpackPwaManifest = require('webpack-pwa-manifest');
const glob = require('glob-all')
// Custom PurgeCSS extractor for Tailwind that allows special characters in
// class names.
//
// https://github.com/FullHuman/purgecss#extractor
class TailwindExtractor {
static extract (content) {
return content.match(/[A-z0-9-:\/]+/g) || []
}
}
module.exports = env => {
return {
mode: env.NODE_ENV === 'prod' ? 'production' : 'development',
resolve: {
extensions: ['.vue', '.css', '.js']
},
node: {
fs: 'empty'
},
entry: {
'main': './src/main.js'
},
output: {
filename: 'bundle.js?[hash]',
publicPath: env.NODE_ENV === 'prod' ? './' : '/'
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
port: 8081,
historyApiFallback: true,
// Enable to allow other (than localhost) machines to access the aepp on your computer
disableHostCheck: false,
host: '0.0.0.0'
},
devtool: env.NODE_ENV === 'prod' ? '' : 'eval-source-map',
plugins: [
new HtmlWebpackPlugin({
inject: true,
// chunks: ['main'],
title: 'Governance Aepp',
template: './src/index.html',
filename: path.join(__dirname, 'dist', 'index.html'),
// Avoids building twice for dev
alwaysWriteToDisk: true
}),
new PurgecssPlugin({
// Specify the locations of any files you want to scan for class names.
paths: glob.sync([
path.join(__dirname, './src/**/*.vue'),
path.join(__dirname, './src/index.html')
]),
extractors: [
{
extractor: TailwindExtractor,
// Specify the file extensions to include when scanning for
// class names.
extensions: ['html', 'js', 'vue']
}
]
}),
new HtmlWebpackHarddiskPlugin(),
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
new WebpackPwaManifest({
name: 'Example Aepp',
short_name: 'Example',
description: 'Your average aepp.',
background_color: '#ff0d6a'
})
],
module: {
rules: [
// this will apply to both plain `.js` files
// AND `<script>` blocks in `.vue` files
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules/@aeternity'),
path.resolve(__dirname, 'node_modules/rlp'),
// Contains 'const' or 'let'
path.resolve(__dirname, 'node_modules/base-x')
],
loader: 'babel-loader'
},
{
type: 'javascript/auto',
test: /\.mjs$/,
include: [
path.resolve(__dirname, 'node_modules/@download/blockies')
],
loader: 'babel-loader'
},
// this will apply to both plain `.css` files
// AND `<style>` blocks in `.vue` files
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js'
}
}
}
]
},
// allows vue compoents in '<template><html><script><style>' syntax
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader'
}
// extractCSS: true
// other vue-loader options go here
}
},
{
test: /\.aes$/,
use: [
'raw-loader'
]
},
{
test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/'
}
}]
}
]
}
}
}