Skip to content

Commit 4ffe6c9

Browse files
committed
Fix support for hot reloading without requiring anything special in the app
1 parent cbdf4d4 commit 4ffe6c9

File tree

5 files changed

+260
-53
lines changed

5 files changed

+260
-53
lines changed

app/Services/Helpers/AssetHashService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function url(string $resource): string
6060
$file = last(explode('/', $resource));
6161
$data = array_get($this->manifest(), $file, $file);
6262

63-
return '/' . ltrim(str_replace($file, array_get($data, 'src', $file), $resource), '/');
63+
return str_replace($file, array_get($data, 'src', $file), $resource);
6464
}
6565

6666
/**

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"webpack-hot-client": "^4.0.2",
4848
"webpack-manifest-plugin": "^2.0.3",
4949
"webpack-serve": "^1.0.2",
50-
"webpack-serve-waitpage": "^1.0.0",
5150
"webpack-shell-plugin": "^0.5.0",
5251
"webpack-stream": "^4.0.3"
5352
},
@@ -56,6 +55,6 @@
5655
"watch": "NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
5756
"build": "NODE_ENV=development ./node_modules/.bin/webpack --progress",
5857
"build:release": "NODE_ENV=production ./node_modules/.bin/webpack",
59-
"serve": "NODE_ENV=development webpack-serve --config ./webpack.config.js"
58+
"serve": "NODE_ENV=development webpack-serve --hot --config ./webpack.config.js"
6059
}
6160
}

resources/assets/scripts/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Vue.use(vuexI18n.plugin, store);
3030
Vue.i18n.add('en', Locales.en);
3131
Vue.i18n.set('en');
3232

33+
if (module.hot) {
34+
module.hot.accept();
35+
}
36+
3337
const router = new VueRouter({
3438
mode: 'history', routes
3539
});

webpack.config.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const _ = require('lodash');
12
const path = require('path');
23
const tailwind = require('tailwindcss');
34
const glob = require('glob-all');
@@ -8,8 +9,6 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
89
const ShellPlugin = require('webpack-shell-plugin');
910
const PurgeCssPlugin = require('purgecss-webpack-plugin');
1011
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
11-
const HTMLWebpackPlugin = require('html-webpack-plugin');
12-
const WebpackServeWaitpage = require('webpack-serve-waitpage');
1312

1413
// Custom PurgeCSS extractor for Tailwind that allows special characters in
1514
// class names.
@@ -29,7 +28,7 @@ const basePlugins = [
2928
'php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js',
3029
],
3130
}),
32-
new ExtractTextPlugin('assets/bundle.css', {
31+
new ExtractTextPlugin('bundle-[hash].css', {
3332
allChunks: true,
3433
}),
3534
new AssetsManifestPlugin({
@@ -38,10 +37,6 @@ const basePlugins = [
3837
integrity: true,
3938
integrityHashes: ['sha384'],
4039
}),
41-
new HTMLWebpackPlugin({
42-
template: './resources/assets/index.html',
43-
filename: 'index.html',
44-
})
4540
];
4641

4742
const productionPlugins = [
@@ -77,9 +72,9 @@ module.exports = {
7772
// Passing an array loads them all but only exports the last.
7873
entry: ['./resources/assets/styles/main.css', './resources/assets/scripts/app.js'],
7974
output: {
80-
path: path.resolve(__dirname, 'public'),
81-
filename: 'assets/bundle.js',
82-
publicPath: '/',
75+
path: path.resolve(__dirname, 'public/assets'),
76+
filename: 'bundle-[hash].js',
77+
publicPath: _.get(process.env, 'PUBLIC_PATH', '') + '/assets/',
8378
crossOriginLoading: 'anonymous',
8479
},
8580
module: {
@@ -133,19 +128,16 @@ module.exports = {
133128
},
134129
plugins: process.env.NODE_ENV === 'production' ? basePlugins.concat(productionPlugins) : basePlugins,
135130
serve: {
136-
host: "0.0.0.0",
137131
content: "./public/",
138132
dev: {
139-
publicPath: "/"
140-
},
141-
hot: {
142-
host: {
143-
server: "0.0.0.0",
144-
client: "192.168.50.2"
133+
publicPath: "/assets/",
134+
headers: {
135+
"Access-Control-Allow-Origin": "*",
145136
}
146137
},
147-
add (app, middleware, options) {
148-
app.use(WebpackServeWaitpage(options, {theme: 'dark'}));
138+
hot: {
139+
hmr: true,
140+
reload: true,
149141
}
150142
}
151143
};

0 commit comments

Comments
 (0)