Skip to content

Commit cc58bc9

Browse files
committed
Switch to uglifyjs for speed improvement, leverage caching
1 parent 9d624d2 commit cc58bc9

File tree

4 files changed

+61
-388
lines changed

4 files changed

+61
-388
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"presets": [
3-
"@babel/preset-env",
4-
"minify"
3+
"@babel/preset-env"
54
],
65
"plugins": [
76
"@babel/plugin-proposal-object-rest-spread"

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
"axios": "^0.18.0",
1515
"babel-cli": "6.18.0",
1616
"babel-loader": "^8.0.0-beta",
17-
"babel-minify": "^0.4.3",
18-
"babel-minify-webpack-plugin": "^0.3.1",
1917
"babel-plugin-transform-object-assign": "^6.22.0",
2018
"babel-plugin-transform-runtime": "^6.23.0",
2119
"babel-plugin-transform-strict-mode": "^6.18.0",
22-
"babel-preset-minify": "^0.4.3",
2320
"babel-register": "^6.26.0",
2421
"clean-webpack-plugin": "^0.1.19",
2522
"css-loader": "^0.28.11",
@@ -36,6 +33,7 @@
3633
"purgecss-webpack-plugin": "^1.1.0",
3734
"style-loader": "^0.21.0",
3835
"tailwindcss": "^0.5.1",
36+
"uglifyjs-webpack-plugin": "^1.2.5",
3937
"vue-devtools": "^3.1.9",
4038
"vue-feather-icons": "^4.7.1",
4139
"vue-loader": "^14.2.2",
@@ -52,8 +50,8 @@
5250
},
5351
"scripts": {
5452
"build:filemanager": "./node_modules/babel-cli/bin/babel.js public/themes/pterodactyl/js/frontend/files/src --source-maps --out-file public/themes/pterodactyl/js/frontend/files/filemanager.min.js",
55-
"watch": "APP_ENV=development ./node_modules/.bin/webpack --watch",
56-
"build": "APP_ENV=development ./node_modules/.bin/webpack",
57-
"build:release": "APP_ENV=production ./node_modules/.bin/webpack"
53+
"watch": "NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
54+
"build": "NODE_ENV=development ./node_modules/.bin/webpack --progress",
55+
"build:release": "NODE_ENV=production ./node_modules/.bin/webpack"
5856
}
5957
}

webpack.config.js

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,65 @@ const AssetsManifestPlugin = require('webpack-assets-manifest');
66
const CleanPlugin = require('clean-webpack-plugin');
77
const ExtractTextPlugin = require('extract-text-webpack-plugin');
88
const ShellPlugin = require('webpack-shell-plugin');
9-
const MinifyPlugin = require('babel-minify-webpack-plugin');
109
const PurgeCssPlugin = require('purgecss-webpack-plugin');
10+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
1111

1212
// Custom PurgeCSS extractor for Tailwind that allows special characters in
1313
// class names.
1414
//
1515
// https://github.com/FullHuman/purgecss#extractor
1616
class TailwindExtractor {
17-
static extract(content) {
17+
static extract (content) {
1818
return content.match(/[A-z0-9-:\/]+/g) || [];
1919
}
2020
}
2121

22+
const basePlugins = [
23+
new CleanPlugin(path.resolve(__dirname, 'public/assets')),
24+
new ShellPlugin({
25+
onBuildStart: [
26+
'php artisan vue-i18n:generate',
27+
'php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js',
28+
],
29+
}),
30+
new ExtractTextPlugin('bundle-[chunkhash].css', {
31+
allChunks: true,
32+
}),
33+
new AssetsManifestPlugin({
34+
writeToDisk: true,
35+
publicPath: true,
36+
integrity: true,
37+
integrityHashes: ['sha384'],
38+
}),
39+
];
40+
41+
const productionPlugins = [
42+
new PurgeCssPlugin({
43+
paths: glob.sync([
44+
path.join(__dirname, 'resources/assets/scripts/**/*.vue'),
45+
path.join(__dirname, 'resources/themes/pterodactyl/**/*.blade.php'),
46+
]),
47+
extractors: [
48+
{
49+
extractor: TailwindExtractor,
50+
extensions: ['html', 'js', 'php', 'vue'],
51+
}
52+
],
53+
}),
54+
new UglifyJsPlugin({
55+
include: [
56+
path.join(__dirname, 'resources/assets/scripts'),
57+
path.join(__dirname, 'node_modules'),
58+
path.join(__dirname, 'vendor/tightenco'),
59+
],
60+
cache: true,
61+
parallel: 2,
62+
}),
63+
];
64+
2265
module.exports = {
23-
mode: process.env.APP_ENV,
24-
devtool: 'source-map',
66+
mode: process.env.NODE_ENV,
67+
devtool: process.env.NODE_ENV === 'production' ? false : 'eval-source-map',
2568
performance: {
2669
hints: false,
2770
},
@@ -38,21 +81,13 @@ module.exports = {
3881
{
3982
test: /\.vue$/,
4083
loader: 'vue-loader',
41-
options: {
42-
postcss: [
43-
require('postcss-import'),
44-
require('postcss-preset-env')({stage: 0}),
45-
tailwind('./tailwind.js'),
46-
require('autoprefixer'),
47-
]
48-
}
4984
},
5085
{
5186
test: /\.js$/,
5287
include: [
5388
path.resolve(__dirname, 'resources'),
5489
],
55-
loader: 'babel-loader',
90+
loader: 'babel-loader?cacheDirectory',
5691
},
5792
{
5893
test: /\.css$/,
@@ -73,7 +108,7 @@ module.exports = {
73108
ident: 'postcss',
74109
plugins: [
75110
require('postcss-import'),
76-
require('tailwindcss')('./tailwind.js'),
111+
tailwind('./tailwind.js'),
77112
require('postcss-preset-env')({stage: 0}),
78113
require('autoprefixer'),
79114
]
@@ -87,44 +122,8 @@ module.exports = {
87122
alias: {
88123
'vue$': 'vue/dist/vue.esm.js'
89124
},
90-
extensions: ['*', '.js', '.vue', '.json']
125+
extensions: ['.js', '.vue', '.json'],
126+
symlinks: false,
91127
},
92-
plugins: [
93-
new PurgeCssPlugin({
94-
paths: glob.sync([
95-
path.join(__dirname, 'resources/assets/scripts/**/*.vue'),
96-
path.join(__dirname, 'resources/themes/pterodactyl/**/*.blade.php'),
97-
]),
98-
extractors: [
99-
{
100-
extractor: TailwindExtractor,
101-
extensions: ['html', 'js', 'php', 'vue'],
102-
}
103-
],
104-
}),
105-
new CleanPlugin(path.resolve(__dirname, 'public/assets')),
106-
new ShellPlugin({
107-
onBuildStart: [
108-
'php artisan vue-i18n:generate',
109-
'php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js',
110-
],
111-
}),
112-
new ExtractTextPlugin('bundle-[chunkhash].css', {
113-
allChunks: true,
114-
}),
115-
new MinifyPlugin({
116-
mangle: {topLevel: true},
117-
}, {
118-
include: [
119-
path.resolve(__dirname, 'resources'),
120-
path.resolve(__dirname, 'node_modules'),
121-
],
122-
}),
123-
new AssetsManifestPlugin({
124-
writeToDisk: true,
125-
publicPath: true,
126-
integrity: true,
127-
integrityHashes: ['sha384'],
128-
}),
129-
]
128+
plugins: process.env.NODE_ENV === 'production' ? basePlugins.concat(productionPlugins) : basePlugins,
130129
};

0 commit comments

Comments
 (0)