Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parcel build not working #43

Closed
raydog99 opened this issue Mar 22, 2021 · 2 comments
Closed

parcel build not working #43

raydog99 opened this issue Mar 22, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@raydog99
Copy link

raydog99 commented Mar 22, 2021

Running 'npm run build' results in a few errors in the compressed files. Namely, the html files in /dist result in "ERR_FILE_NOT_FOUND" as they try to find each other.

It looks like "parcel build" has an issue with relative assets: parcel-bundler/parcel#206

A partial solution is, on line 44 in tools/build.sh, add: "--public-url ./"

But the files in articles and work still have the relative path error. Not sure how others haven't run into this issue.

@parksb parksb added the bug Something isn't working label Mar 23, 2021
@raydog99
Copy link
Author

raydog99 commented Mar 23, 2021

My guess is parcel build expects all files to be in the same directory, but article and work end up as child directories in /dist.

Ex: dist/article/0.html will look for navigation.html as './navigation.html' when it should be looking at '../navigation.html'. I couldn't find ways for parcel to fix this.

One workaround is to just write a script that fixes the paths in child directories:

from os import listdir
from os.path import isfile, join
import fileinput
from bs4 import BeautifulSoup

def path_replace(src_dir):
	files = [f for f in listdir(src_dir) if isfile(join(src_dir, f)) and f.endswith('.html')]

	for single_file in files:
		soup = BeautifulSoup(open(src_dir + single_file), 'html.parser')

		links = soup.find_all(href=True)
		links = list(filter(lambda x: x['href'].endswith(('.css', '.ico', '.html', '.js')), links))

		for link in links:
			link['href'] = '../' + link['href']

		src_links = soup.find_all(src=True)
		src_links = list(filter(lambda x: x['src'].endswith(('.css', '.ico', '.html', '.js')), src_links))

		for link in src_links:
			link['src'] = '../' + link['src']


		with open(src_dir + single_file, 'w') as fp:
			fp.write(soup.prettify())


dirs = ['dist/article/', 'dist/work/']
for folder in dirs:
	path_replace(folder)

You can automate this by adding python3 tools/path_replacer.py at the bottom of tools/build.sh.

In articles.ejs, works.ejs, replace the navigation header element with the code in navigation.ejs and replace the header-id from "top-container" to "nav-styling". Copy the code in navigation.scss to the bottom of init.scss, renaming "top-container" to "nav-styling".

This is not the ideal solution, so leaving this open until someone finds the right way to use parcel to resolve it.

@parksb
Copy link
Owner

parksb commented May 20, 2022

I just removed parcel from this project. Thank you for reporting.

@parksb parksb closed this as completed May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants