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');
|
2019-02-03 02:33:12 +01:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-06-04 03:46:27 +02:00
|
|
|
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');
|
2019-02-03 02:33:12 +01:00
|
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
2018-12-16 23:30:21 +01:00
|
|
|
|
2019-02-03 02:33:12 +01:00
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
2018-06-04 03:03:46 +02:00
|
|
|
|
2019-02-03 02:33:12 +01:00
|
|
|
let plugins = [
|
2018-06-04 05:34:30 +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',
|
|
|
|
],
|
|
|
|
}),
|
2019-02-03 03:25:33 +01:00
|
|
|
new MiniCssExtractPlugin({ filename: isProduction ? 'bundle.[chunkhash:8].css' : 'bundle.[hash:8].css' }),
|
2018-06-04 05:34:30 +02:00
|
|
|
new AssetsManifestPlugin({
|
|
|
|
writeToDisk: true,
|
|
|
|
publicPath: true,
|
|
|
|
integrity: true,
|
|
|
|
integrityHashes: ['sha384'],
|
|
|
|
}),
|
2019-02-03 02:33:12 +01:00
|
|
|
new VueLoaderPlugin(),
|
2018-06-04 05:34:30 +02:00
|
|
|
];
|
|
|
|
|
2019-02-03 02:33:12 +01:00
|
|
|
if (isProduction) {
|
|
|
|
plugins = plugins.concat([
|
|
|
|
new PurgeCssPlugin({
|
|
|
|
paths: glob.sync([
|
|
|
|
path.join(__dirname, 'resources/assets/scripts/**/*.vue'),
|
|
|
|
path.join(__dirname, 'resources/assets/scripts/**/*.ts'),
|
|
|
|
path.join(__dirname, 'resources/themes/pterodactyl/**/*.blade.php'),
|
|
|
|
]),
|
|
|
|
// 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$/],
|
|
|
|
extractors: [
|
|
|
|
{
|
|
|
|
extractor: class {
|
|
|
|
static extract (content) {
|
|
|
|
return content.match(/[A-z0-9-:\/]+/g) || [];
|
|
|
|
}
|
|
|
|
},
|
2019-02-03 03:25:33 +01:00
|
|
|
extensions: ['html', 'ts', 'js', 'php', 'vue'],
|
2019-02-03 02:33:12 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const typescriptLoaders = [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: !isProduction,
|
|
|
|
presets: ['@babel/preset-env'],
|
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
['@babel/plugin-proposal-object-rest-spread', { 'useBuiltIns': true }]
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
appendTsSuffixTo: [/\.vue$/],
|
|
|
|
experimentalWatchApi: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const cssLoaders = [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !isProduction,
|
|
|
|
importLoaders: 1,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ loader: 'resolve-url-loader' },
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
sourceMap: true,
|
|
|
|
plugins: [
|
|
|
|
require('postcss-import'),
|
|
|
|
tailwind('./tailwind.js'),
|
|
|
|
require('postcss-preset-env')({
|
|
|
|
stage: 2,
|
|
|
|
}),
|
|
|
|
require('precss'),
|
|
|
|
].concat(isProduction ? require('cssnano') : []),
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 05:34:30 +02:00
|
|
|
];
|
|
|
|
|
2018-03-31 06:58:38 +02:00
|
|
|
module.exports = {
|
2019-02-03 03:49:51 +01:00
|
|
|
target: 'web',
|
2018-06-04 05:34:30 +02:00
|
|
|
mode: process.env.NODE_ENV,
|
2019-02-03 02:33:12 +01:00
|
|
|
devtool: isProduction ? false : 'inline-source-map',
|
2018-06-04 02:40:35 +02:00
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
2018-12-30 01:11:49 +01:00
|
|
|
entry: ['./resources/assets/styles/main.css', './resources/assets/scripts/app.ts'],
|
2018-03-31 06:58:38 +02:00
|
|
|
output: {
|
2018-06-07 06:44:52 +02:00
|
|
|
path: path.resolve(__dirname, 'public/assets'),
|
2019-02-03 03:25:33 +01:00
|
|
|
filename: isProduction ? 'bundle.[chunkhash:8].js' : 'bundle.[hash:8].js',
|
|
|
|
chunkFilename: isProduction ? '[name].[chunkhash:8].js' : '[name].[hash:8].js',
|
2018-06-07 06:44:52 +02:00
|
|
|
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',
|
|
|
|
},
|
2019-02-03 03:25:33 +01:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: !isProduction,
|
|
|
|
presets: ['@babel/preset-env'],
|
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
['@babel/plugin-proposal-object-rest-spread', { 'useBuiltIns': true }]
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2018-12-16 23:30:21 +01:00
|
|
|
{
|
2018-12-30 00:51:13 +01:00
|
|
|
test: /\.ts$/,
|
2018-12-16 23:30:21 +01:00
|
|
|
exclude: /node_modules/,
|
2019-02-03 02:33:12 +01:00
|
|
|
use: typescriptLoaders,
|
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
|
|
|
],
|
2019-02-03 02:33:12 +01:00
|
|
|
use: cssLoaders,
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|svg)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
2019-02-03 02:33:12 +01:00
|
|
|
name: '[name].[ext]?[hash:8]',
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
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
|
|
|
},
|
2019-02-03 02:33:12 +01:00
|
|
|
plugins: plugins,
|
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: !isProduction ? [] : [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
|
|
|
uglifyOptions: {
|
|
|
|
output: {
|
|
|
|
comments: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2019-02-03 03:25:33 +01:00
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
vue: {
|
|
|
|
test: /[\\/]node_modules[\\/](vue\w?)[\\/]/,
|
|
|
|
name: 'vue',
|
|
|
|
chunks: 'initial',
|
|
|
|
},
|
|
|
|
locales: {
|
|
|
|
test: /locales/,
|
|
|
|
name: 'locales',
|
|
|
|
chunks: 'initial',
|
|
|
|
},
|
|
|
|
vendors: {
|
|
|
|
test: /[\\/]node_modules[\\/](?!vue)(.*)[\\/]/,
|
|
|
|
name: 'vendor',
|
|
|
|
chunks: 'initial',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-02-03 02:33:12 +01:00
|
|
|
},
|
|
|
|
devServer: {
|
|
|
|
contentBase: path.join(__dirname, 'public'),
|
2019-02-03 03:49:51 +01:00
|
|
|
publicPath: _.get(process.env, 'PUBLIC_PATH', '') + '/assets/',
|
2019-02-03 02:33:12 +01:00
|
|
|
allowedHosts: [
|
|
|
|
'.pterodactyl.test',
|
|
|
|
],
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
2018-12-16 23:30:21 +01:00
|
|
|
},
|
|
|
|
},
|
2018-03-31 06:58:38 +02:00
|
|
|
};
|