Answer the question
In order to leave comments, you need to log in
How to properly set up SSR on laravel + react.js?
For some reason, laravel swears at webpack roughly speaking, it says that it is impossible to execute the file because it contains a window
object
using https://github.com/spatie/laravel-server-side-rendering
here is the webpack config:
const CleanWebpackPlugin = require("clean-webpack-plugin"); //installed via npm
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const uniqid = require("uniqid");
let mix = require("laravel-mix");
let webpack = require("webpack");
let CompressionPlugin = require("compression-webpack-plugin");
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix
.react("resources/assets/js/app.js", "public/js")
.react("resources/assets/js/app-server.js", "public/js")
.sass("resources/assets/sass/app.scss", "public/css")
.version();
let plugins = [new CleanWebpackPlugin(["public/js/*"])];
if (process.env.NODE_ENV === "production") {
plugins.push(
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true
},
sourceMap: true
})
);
plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
plugins.push(
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
);
}
mix.webpackConfig({
output: {
// filename: "js/app.js",
chunkFilename: "js/[name]." + uniqid() + ".bundle.js",
pathinfo: true
},
plugins: plugins
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question