2018-06-07 06:44:52 +02:00
|
|
|
const _ = require('lodash');
|
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:50:58 +02:00
|
|
|
const PurgeCssPlugin = require('purgecss-webpack-plugin');
|
2018-06-04 05:34:30 +02:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2018-12-16 23:30:21 +01:00
|
|
|
|
2018-06-04 04:50:58 +02:00
|
|
|
// Custom PurgeCSS extractor for Tailwind that allows special characters in
|
|
|
|
// class names.
|
|
|
|
//
|
|
|
|
// https://github.com/FullHuman/purgecss#extractor
|
|
|
|
class TailwindExtractor {
|
2018-06-04 05:34:30 +02:00
|
|
|
static extract (content) {
|
2018-06-04 04:50:58 +02:00
|
|
|
return content.match(/[A-z0-9-:\/]+/g) || [];
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 03:03:46 +02:00
|
|
|
|
2018-06-04 05:34:30 +02:00
|
|
|
const basePlugins = [
|
|
|
|
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-07 06:44:52 +02:00
|
|
|
new ExtractTextPlugin('bundle-[hash].css', {
|
2018-06-04 05:34:30 +02:00
|
|
|
allChunks: true,
|
|
|
|
}),
|
|
|
|
new AssetsManifestPlugin({
|
|
|
|
writeToDisk: true,
|
|
|
|
publicPath: true,
|
|
|
|
integrity: true,
|
|
|
|
integrityHashes: ['sha384'],
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
const productionPlugins = [
|
|
|
|
new PurgeCssPlugin({
|
|
|
|
paths: glob.sync([
|
|
|
|
path.join(__dirname, 'resources/assets/scripts/**/*.vue'),
|
|
|
|
path.join(__dirname, 'resources/themes/pterodactyl/**/*.blade.php'),
|
|
|
|
]),
|
2018-06-17 02:13:03 +02:00
|
|
|
// Don't let PurgeCSS remove classes ending with -enter or -leave-active
|
|
|
|
// They're used by Vue transitions and are therefore not specifically defined
|
|
|
|
// in any of the files are are checked by PurgeCSS.
|
|
|
|
whitelistPatterns: [/-enter$/, /-leave-active$/],
|
2018-06-04 05:34:30 +02:00
|
|
|
extractors: [
|
|
|
|
{
|
|
|
|
extractor: TailwindExtractor,
|
|
|
|
extensions: ['html', 'js', 'php', 'vue'],
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
2018-06-04 05:34:30 +02:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
include: [
|
|
|
|
path.join(__dirname, 'resources/assets/scripts'),
|
|
|
|
path.join(__dirname, 'node_modules'),
|
|
|
|
path.join(__dirname, 'vendor/tightenco'),
|
|
|
|
],
|
|
|
|
cache: true,
|
|
|
|
parallel: 2,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
2018-03-31 06:58:38 +02:00
|
|
|
module.exports = {
|
2018-06-04 05:34:30 +02:00
|
|
|
mode: process.env.NODE_ENV,
|
2018-07-22 01:22:41 +02:00
|
|
|
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-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.
|
2018-09-14 06:53:12 +02:00
|
|
|
entry: ['./resources/assets/styles/main.css', './resources/assets/scripts/app.js'],
|
2018-03-31 06:58:38 +02:00
|
|
|
output: {
|
2018-06-07 06:44:52 +02:00
|
|
|
path: path.resolve(__dirname, 'public/assets'),
|
|
|
|
filename: 'bundle-[hash].js',
|
|
|
|
publicPath: _.get(process.env, 'PUBLIC_PATH', '') + '/assets/',
|
2018-06-04 03:46:27 +02:00
|
|
|
crossOriginLoading: 'anonymous',
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
},
|
2018-12-16 23:30:21 +01:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loader: 'ts-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
options: {
|
|
|
|
appendTsSuffixTo: [/\.vue$/],
|
|
|
|
},
|
|
|
|
},
|
2018-03-31 06:58:38 +02:00
|
|
|
{
|
|
|
|
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 05:34:30 +02:00
|
|
|
loader: 'babel-loader?cacheDirectory',
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2018-05-28 23:16:03 +02:00
|
|
|
{
|
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: {
|
2018-06-11 00:32:07 +02:00
|
|
|
sourceMap: true,
|
2018-06-04 04:50:58 +02:00
|
|
|
importLoaders: 1,
|
|
|
|
},
|
2018-06-04 04:35:50 +02:00
|
|
|
}, {
|
|
|
|
loader: 'postcss-loader',
|
2018-06-04 03:46:27 +02:00
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
2018-06-11 00:32:07 +02:00
|
|
|
sourceMap: true,
|
2018-06-04 03:46:27 +02:00
|
|
|
plugins: [
|
|
|
|
require('postcss-import'),
|
2018-06-04 05:34:30 +02:00
|
|
|
tailwind('./tailwind.js'),
|
2018-12-16 23:30:21 +01:00
|
|
|
require('postcss-preset-env')({ stage: 0 }),
|
2018-06-11 00:32:07 +02:00
|
|
|
require('precss'),
|
2018-06-04 03:46:27 +02:00
|
|
|
require('autoprefixer'),
|
2018-06-11 00:32:07 +02:00
|
|
|
require('cssnano'),
|
2018-12-16 23:30:21 +01:00
|
|
|
],
|
2018-06-04 03:46:27 +02:00
|
|
|
},
|
|
|
|
}],
|
|
|
|
}),
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|svg)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]?[hash]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
2018-12-16 23:30:21 +01:00
|
|
|
extensions: ['.ts', '.js', '.vue', '.json'],
|
2018-03-31 06:58:38 +02:00
|
|
|
alias: {
|
2018-12-16 23:30:21 +01:00
|
|
|
'vue$': 'vue/dist/vue.esm.js',
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2018-06-04 05:34:30 +02:00
|
|
|
symlinks: false,
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2018-06-04 05:34:30 +02:00
|
|
|
plugins: process.env.NODE_ENV === 'production' ? basePlugins.concat(productionPlugins) : basePlugins,
|
2018-06-06 22:33:24 +02:00
|
|
|
serve: {
|
2018-12-16 23:30:21 +01:00
|
|
|
content: './public/',
|
2018-06-06 22:33:24 +02:00
|
|
|
dev: {
|
2018-12-16 23:30:21 +01:00
|
|
|
publicPath: '/assets/',
|
2018-06-07 06:44:52 +02:00
|
|
|
headers: {
|
2018-12-16 23:30:21 +01:00
|
|
|
'Access-Control-Allow-Origin': '*',
|
2018-06-11 00:32:07 +02:00
|
|
|
},
|
2018-06-06 22:33:24 +02:00
|
|
|
},
|
2018-06-07 06:44:52 +02:00
|
|
|
hot: {
|
|
|
|
hmr: true,
|
|
|
|
reload: true,
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
|
|
|
},
|
2018-03-31 06:58:38 +02:00
|
|
|
};
|