Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Fix assets helpers #1030

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buffalo/cmd/updater/webpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions generators/assets/webpack/templates/webpack.config.js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions render/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion render/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down