diff --git a/buffalo/cmd/updater/webpack.go b/buffalo/cmd/updater/webpack.go index bafc390a1..f764ad5ad 100644 --- a/buffalo/cmd/updater/webpack.go +++ b/buffalo/cmd/updater/webpack.go @@ -60,6 +60,10 @@ func WebpackCheck(r *Runner) error { if !ask("Your webpack.config.js file is different from the latest Buffalo template.\nWould you like to replace yours with the latest template?") { fmt.Println("\tSkipping webpack.config.js") + if !bytes.Contains(b, []byte("publicPath:")) { + r.Warnings = append(r.Warnings, `It seems your webpack.config.js file doesn't define a "publicPath". You need to define it MANUALLY in the "output" section to ensure assets helpers work correctly. +See https://webpack.js.org/guides/public-path/`) + } return nil } diff --git a/generators/assets/webpack/templates/webpack.config.js.tmpl b/generators/assets/webpack/templates/webpack.config.js.tmpl index 9ab8ed91b..d9451ea5b 100644 --- a/generators/assets/webpack/templates/webpack.config.js.tmpl +++ b/generators/assets/webpack/templates/webpack.config.js.tmpl @@ -73,11 +73,12 @@ const configurator = { buildConfig: function(){ const env = process.env.NODE_ENV || "development"; - + const ASSET_PATH = process.env.ASSET_PATH || "/assets/"; + var config = { mode: env, entry: configurator.entries(), - output: {filename: "[name].[hash].js", path: `${__dirname}/public/assets`}, + output: {filename: "[name].[hash].js", path: `${__dirname}/public/assets`, publicPath: ASSET_PATH}, plugins: configurator.plugins(), module: configurator.moduleOptions() } diff --git a/render/template_helpers.go b/render/template_helpers.go index 4346e0d0b..5ce7552bd 100644 --- a/render/template_helpers.go +++ b/render/template_helpers.go @@ -27,9 +27,9 @@ func assetPathFor(file string) string { filePath := assetMap[file] if filePath == "" { - filePath = file + filePath = filepath.Join("/assets", file) } - return filepath.ToSlash(filepath.Join("/assets", filePath)) + return filepath.ToSlash(filePath) } type helperTag struct { diff --git a/render/template_test.go b/render/template_test.go index 34199925e..d292d22f5 100644 --- a/render/template_test.go +++ b/render/template_test.go @@ -71,7 +71,7 @@ func Test_AssetPath(t *testing.T) { }).Template ioutil.WriteFile(filepath.Join(aDir, "manifest.json"), []byte(`{ - "application.css": "application.aabbc123.css" + "application.css": "/assets/application.aabbc123.css" }`), 0644) for original, expected := range cases {