diff --git a/flow-server/src/main/java/com/vaadin/flow/server/startup/DevModeInitializer.java b/flow-server/src/main/java/com/vaadin/flow/server/startup/DevModeInitializer.java index ee60e1f4b5b..e8d1d20665e 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/startup/DevModeInitializer.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/startup/DevModeInitializer.java @@ -89,6 +89,7 @@ import elemental.json.JsonObject; import static com.vaadin.flow.server.Constants.PACKAGE_JSON; +import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES; import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE; import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR; import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR; @@ -287,10 +288,11 @@ public static void initDevModeHandler(Set> classes, File generatedPackages = new File(builder.generatedFolder, PACKAGE_JSON); - + File target = new File(baseDir, "target"); // Always update to auto-generated webpack configuration - builder.withWebpack(builder.npmFolder, FrontendUtils.WEBPACK_CONFIG, - FrontendUtils.WEBPACK_GENERATED); + builder.withWebpack( + new File(target, "classes/" + VAADIN_SERVLET_RESOURCES), + FrontendUtils.WEBPACK_CONFIG, FrontendUtils.WEBPACK_GENERATED); // If we are missing either the base or generated package json files // generate those diff --git a/flow-server/src/test/java/com/vaadin/flow/server/startup/DevModeInitializerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/startup/DevModeInitializerTest.java index 41ff49579fa..62182c62d6a 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/startup/DevModeInitializerTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/startup/DevModeInitializerTest.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Set; import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.jcip.annotations.NotThreadSafe; @@ -245,6 +247,33 @@ public void should_Always_Update_Generated_Webpack_Conf() throws Exception { } } + @Test + public void generated_output_should_be_in_target_classes() + throws Exception { + File generatedWebpackFile = new File(webpackFile.getParentFile(), + FrontendUtils.WEBPACK_GENERATED); + try (FileWriter writer = new FileWriter(generatedWebpackFile)) { + process(); + + final String generated = IOUtils.toString( + generatedWebpackFile.toURI(), StandardCharsets.UTF_8); + + final Pattern compile = Pattern.compile( + "projectStaticAssetsOutputFolder.* '(.*)'"); + final Matcher matcher = compile.matcher(generated); + matcher.find(); + + Assert.assertTrue( + "Generated webpack configuration contained faulty path ยด" + + matcher.group(1) + + "' instead of 'target/classes/META-INF/VAADIN/static'", + generated.contains( + "const projectStaticAssetsOutputFolder = require('path').resolve(__dirname, 'target/classes/META-INF/VAADIN/static');")); + } finally { + generatedWebpackFile.delete(); + } + } + @Test public void should_Run_Updaters_doesNotThrow() throws Exception { // no any exception means that updaters are executed and dev mode server