-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
97 lines (93 loc) · 2.49 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
const path = require('path')
const glob = require('glob-all')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const PurgeCSSPlugin = require('purgecss-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
// 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-Za-z0-9-_:\\/]+/g) || []
}
}
const webpackConfig = {
entry: ['./resources/assets/js/app.js', './resources/assets/css/app.css'],
output: {
path: path.resolve(__dirname, 'public/dist'),
filename: 'app_[chunkhash].js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
filename: 'public/dist/app_[contenthash].css',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader'
]
})
}
]
},
plugins: [
new CleanWebpackPlugin(['public/dist']),
new ExtractTextPlugin('app_[chunkhash].css'),
new ManifestPlugin({
fileName: path.resolve(__dirname, 'public/mix-manifest.json'),
publicPath: '/dist/',
generate: (seed, files) =>
files.reduce(
(manifest, { name, path }) => ({
...manifest,
[`/dist/app${name.replace('main', '')}`]: path
}),
seed
)
})
]
}
module.exports = (env, options) => {
if (options.mode === 'production') {
webpackConfig.plugins = [
...webpackConfig.plugins,
new PurgeCSSPlugin({
paths: glob.sync([
path.join(__dirname, 'resources/views/**/*.blade.php')
]),
extractors: [
{
extractor: TailwindExtractor,
extensions: ['html', 'js', 'php']
}
]
}),
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
safe: true,
discardComments: { removeAll: true }
}
})
]
}
return webpackConfig
}