我目前正在使用npx webpack
进行手动重新加载,这非常耗时。
因此,尝试使用Webpack docs和this tutorial
当我运行npm start
时,它不会引发任何错误,告诉我已生成文件,但是这些文件在目标目录/dist
中不可用。如果它们放在其他地方,我找不到。
同样,HMR似乎在某种意义上起作用,因为一旦对应用程序文件进行了更改,它就会自动重新编译。
它也会自动打开localhost:8080
,但仅显示目录列表或类似CANNOT GET
的消息。
顺便说一句,我不使用Symfony Encore。
目录如下所示:
- bin
- client // where the React files are
- config // Symfony
- node_modules
- public
- dist // here goes Webpack's output ( normally )
- index.php
- src // Symfony app files
- templates - Twig
- var
- vendor
webpack.config.js
上面的webpack.config.js如下图所示,是最新的配置尝试
const webpack = require('webpack');
const { InjectManifest } = require('workbox-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const path = require('path');
const usedevserver = true;
const publicPath = usedevserver ? 'http://localhost:8080/public/dist/' : '/dist/';
console.log('path',path.resolve(__dirname,'public/dist'));
console.log('public path',publicPath);
module.exports = {
mode: 'development',entry: './client/index.js',output: {
path: path.resolve(__dirname,'public/dist'),filename: '[name].[hash].js',publicPath,},devtool: 'inline-source-map',module: {
....
},devserver: {
// contentBase: './dist',hot: true,allowedHosts: [
'http://127.0.0.1:8000','http://127.0.0.1:8001','http://localhost:8000','http://localhost:8001',],plugins: [
new webpack.HotModuleReplacementPlugin(),...