Pterodactyl-Panel/webpack.config.js

131 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-06-04 03:03:46 +02:00
const path = require('path');
2018-06-04 04:50:58 +02:00
const tailwind = require('tailwindcss');
const glob = require('glob-all');
2018-06-04 04:35:50 +02:00
const AssetsManifestPlugin = require('webpack-assets-manifest');
2018-06-04 03:46:27 +02:00
const CleanPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ShellPlugin = require('webpack-shell-plugin');
2018-06-04 04:35:50 +02:00
const MinifyPlugin = require('babel-minify-webpack-plugin');
2018-06-04 04:50:58 +02:00
const PurgeCssPlugin = require('purgecss-webpack-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-z0-9-:\/]+/g) || [];
}
}
2018-06-04 03:03:46 +02:00
module.exports = {
2018-06-04 02:40:35 +02:00
mode: 'development',
2018-06-04 03:03:46 +02:00
devtool: 'source-map',
2018-06-04 02:40:35 +02:00
performance: {
hints: false,
},
2018-06-04 03:46:27 +02:00
// Passing an array loads them all but only exports the last.
entry: ['./resources/assets/styles/main.css', './resources/assets/scripts/app.js'],
output: {
2018-06-04 03:46:27 +02:00
path: path.resolve(__dirname, 'public/assets'),
2018-06-04 03:53:27 +02:00
filename: 'bundle-[chunkhash].js',
2018-06-04 03:46:27 +02:00
publicPath: '/assets/',
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
postcss: [
require('postcss-import'),
require('postcss-preset-env')({stage: 0}),
2018-06-04 04:50:58 +02:00
tailwind('./tailwind.js'),
require('autoprefixer'),
]
}
},
{
test: /\.js$/,
2018-06-04 03:03:46 +02:00
include: [
2018-06-04 04:35:50 +02:00
path.resolve(__dirname, 'resources'),
2018-06-04 03:03:46 +02:00
],
2018-06-04 03:46:27 +02:00
loader: 'babel-loader',
},
2018-06-04 03:46:27 +02:00
{
test: /\.css$/,
include: [
2018-06-04 04:35:50 +02:00
path.resolve(__dirname, 'resources'),
2018-06-04 03:46:27 +02:00
],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
2018-06-04 04:35:50 +02:00
use: [{
loader: 'css-loader',
2018-06-04 04:50:58 +02:00
options: {
importLoaders: 1,
minimize: true,
},
2018-06-04 04:35:50 +02:00
}, {
loader: 'postcss-loader',
2018-06-04 03:46:27 +02:00
options: {
ident: 'postcss',
plugins: [
require('postcss-import'),
require('tailwindcss')('./tailwind.js'),
2018-06-04 04:40:05 +02:00
require('postcss-preset-env')({stage: 0}),
2018-06-04 03:46:27 +02:00
require('autoprefixer'),
]
},
}],
}),
}
]
},
resolve: {
alias: {
2018-03-31 22:51:18 +02:00
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
2018-06-04 03:03:46 +02:00
plugins: [
2018-06-04 04:50:58 +02:00
new PurgeCssPlugin({
paths: glob.sync([
path.join(__dirname, 'resources/assets/scripts/**/*.vue'),
path.join(__dirname, 'resources/themes/pterodactyl/**/*.blade.php'),
]),
extractors: [
{
extractor: TailwindExtractor,
extensions: ['html', 'js', 'php', 'vue'],
}
],
}),
2018-06-04 03:46:27 +02:00
new CleanPlugin(path.resolve(__dirname, 'public/assets')),
new ShellPlugin({
onBuildStart: [
'php artisan vue-i18n:generate',
'php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js',
],
}),
2018-06-04 03:53:27 +02:00
new ExtractTextPlugin('bundle-[chunkhash].css', {
2018-06-04 03:46:27 +02:00
allChunks: true,
}),
2018-06-04 04:35:50 +02:00
new MinifyPlugin({
mangle: {topLevel: true},
}, {
2018-06-04 03:03:46 +02:00
include: [
2018-06-04 04:35:50 +02:00
path.resolve(__dirname, 'resources'),
path.resolve(__dirname, 'node_modules'),
2018-06-04 03:03:46 +02:00
],
}),
2018-06-04 04:35:50 +02:00
new AssetsManifestPlugin({
writeToDisk: true,
publicPath: true,
integrity: true,
integrityHashes: ['sha384'],
}),
2018-06-04 03:03:46 +02:00
]
};