我正在尝试在春季启动中为React应用设置热模块替换(或至少是热重载),它编译良好,并在我运行应用时显示控制台日志,但是当我执行更改了这些日志,尽管没有任何更改:
[WDS] Hot Module Replacement enabled.
[WDS] App hot update...
[HMR] Checking for updates on the server...
[WDS] App hot update...
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ofuscated</groupId>
<artifactId>ofuscated</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ofuscated</name>
<description>Ofuscated Application</description>
<repositories>
<repository>
<id>ofuscatedcentral</id>
<name>Ofuscated Central Repo</name>
<url>http://mvn.ofuscated.com:8081/nexus/content/groups/public</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Repo</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.ofuscated</groupId>
<artifactId>service-starter</artifactId>
<version>0.0.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.ofuscated</groupId>
<artifactId>memcached-spring-sessions</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>com.ofuscated</groupId>
<artifactId>vault-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
<dependency>
<groupId>com.ofuscated</groupId>
<artifactId>monitoring-metrics-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.ofuscated</groupId>
<artifactId>dfs-java-client</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>ofuscated</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<outputDirectory>${project.build.directory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<!-- See https://nodejs.org/en/download/ for latest Node version -->
<nodeVersion>v10.10.0</nodeVersion>
<!-- See https://yarnpkg.com/en/ for latest Yarn Version -->
<yarnVersion>v1.9.4</yarnVersion>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
<execution>
<id>yarn gulp</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>gulp</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
webpack.config.dev.js
const path = require('path');
const WriteFilePlugin = require('write-file-webpack-plugin');
const webpack = require('webpack');
const paths = require('./paths');
const webpackModules = require('./webpack.modules');
// Use the same ruleset for all the outputs
const configDev = {
devServer: {
historyApiFallback: true,
port: 9090,
proxy: {
'/': {
// Force update in Spring Boot
target: 'http://localhost:8081',
secure: false,
prependPath: false,
},
},
hotOnly: true,
// Create proxied port to avoid collisions
publicPath: 'http://localhost:8081/',
},
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
// Check for eslint errors
enforce: 'pre',
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
fix: true,
cache: true,
failOnError: true,
},
},
{
// Compile main index
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
cacheDirectory: true,
presets: ['env', 'react', 'stage-0'],
plugins: ['react-hot-loader/babel'],
},
},
],
},
plugins: [new WriteFilePlugin(), new webpack.HotModuleReplacementPlugin()],
resolve: {
extensions: ['.js', '.jsx'],
modules: [path.resolve('./src'), path.resolve('./node_modules')],
},
stats: 'errors-only',
watchOptions: {
ignored: [paths.salesReactFolder, 'node_modules'],
},
};
module.exports = webpackModules.map((module) => Object.assign(module, configDev));
我正在使用webpack-dev-server --config ./webpack/webpack.config.dev.js
运行它,这是一个已经存在的React App,我正在尝试使用它来设置webpack。
最初,我添加了一个{AppContainer} from react-hot-loader
来包装主应用程序,并且在应用程序内部我正在使用{hot} from react-hot-loader
。
我的目标是为React应用程序更换热模块,但最小的可行性是重新加载,我将不胜感激!