"scripts": {
"dev": "node build.js",
"build": "node build.js"
}
const rimraf = require('rimraf');
const Bundler = require('parcel-bundler');
const Path = require('path');
rimraf(Path.join(__dirname, './dist') , () => {
console.log('Removed dist folder');
});
if (process.env.NODE_ENV === 'production') {
rimraf(Path.join(__dirname, './.cache') , () => {
console.log('Removed cache folder');
});
}
const entryFiles = [
Path.join(__dirname, './src/index.html'),
Path.join(__dirname, './src/index2.html')
];
const bundler = new Bundler(entryFiles);
bundler.on('bundled', (bundle) => {
console.log("Bundling done");
});
bundler.bundle();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport" />
<title></title>
</head>
<body>
<script src="./index.js"></script>
<h1>Index.html</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport" />
<title></title>
</head>
<body>
<script src="./index.js"></script>
<h1>Index2.html</h1>
</body>
</html>
import './index.css'
body {
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport">
<title></title>
<link rel="stylesheet" href="/src.e31bb0bc.css"></head>
<body>
<script src="/src.e31bb0bc.js"></script>
<h1>Index.html</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport">
<title></title>
</head>
<body>
<script src="/src.e31bb0bc.js"></script>
<h1>Index2.html</h1>
</body>
</html>
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.10.3 |
| Node | 11.3.0 |
| npm/Yarn | npm 6.4.1 |
| Operating System |
I've been digging a bit, and I've found where the bug occurs.
Here, the bundler rejects creating a new bundle for the index.js
asset as a child of index2.html
, since it's already been created as a child of index.html
, and therefore is an entry point for the index.js
bundle created at that point.
I'm not sure how to fix the issue, but at that point, somehow the asset must still be registered on the bundle, so that the lookup here can find it.
Any updates?
If I'm not mistaken, the current work around is to create an index for each entry point?
index-main.js
for index.html
index-about.js
for about.html
package any pug files meet the same issue.
any news?
Temp solution:
src/
βββ pages/
β βββ about.js
β βββ about.html
β βββ index.js
β βββ index.html
βββ shared.js
src/shared.js
import "./styles.scss";
import "jquery/dist/jquery.slim.js";
import "bootstrap";
src/pages/about.js
import "../shared.js";
src/pages/about.html
<script src="about.js"></script>
src/pages/index.js
import "../shared.js";
src/pages/index.html
<script src="index.js"></script>
I have the same issue. The solution that @maximelebreton suggested kind of helped me for now, but I prefer to keep all pages on the first layer of src/, so my structure looks like this:
src/
βββ assets/
β βββ ...
βββ js-linkers/
β βββ page2.js
β βββ page3.js
βββ index.html
βββ index.js
βββ page2.html
βββ page3.html
Where in index.js I have all asset imports, and if I want to create some other page, I add page2.html and link to an auxiliary page2.js file with the only line inside import '../index.js';
.
Unfortunately you need to create the specific js linker file for an every new html page. It may make the src/ folder kind of messy, so I tidy up them to some folder. But at least for me the advantage will be that urls remain more obvious.
@mischnic The original issue was reported more than a year ago. Any update so far?
@sergeyzwezdin I've just tested this with Parcel 2, it's fixed.
(Not sure if this was explained already, but Parcel 1 didn't allow any circles in the asset tree, so an asset couldn't be used in more than one bundle. Parcel 2 allows this just fine.)
@mischnic When it's going to be published?
The current alpha version works as expected.
@mischnic ok, but when it will be published as a stable version? I wouldn't like to use alpha.
The current alpha version works as expected.
Which one is it please? I've tried 2.0.0-nightly.85 - not working.
@equistx Please provide a (small) code sample
βββ pages/
β βββ page1.html
β βββ page2.html
β βββ index.js
β βββ index.scss
index.js: import './index.scss';
index.scss: body {background: black;}
page1.html & page2.html inside body tag: <script src="index.js"></script>
cmd: parcel pages/*.html
localhost:1234/page1.html - has black body and css linked inside head tag
localhost:1234/page2.html - has not
@mischnic I'm sorry and thank you, my fault, it is working. I've been using wrong version, because I had somehow parcel
and parcel-bundle
installed concurrently (not somehow rly, but because there is parcel-bundle
in docs vs parcel
in git installation guide - I see the difference now, didn't notice earlier). Of course, every cmd parcel
command was related to parcel-bundle
, instead of to parcel@alpha
one.
Unfortunately I can't use working alpha, since HMR stopped working after I switched from parcel-bundle
to parcel
. Changes made inside @import
ed sass files are not detected therefore browser doesn't reload.
As suggested here, I had to remove the main
field in package.json
and run parcel build src/**/*.html
, and then they should all build.
Unfortunately I can't use working alpha, since HMR stopped working after I switched from parcel-bundle to parcel. Changes made inside @imported sass files are not detected therefore browser doesn't reload.
After some time, I got back to this. Unfortunately, issue is still there on 2.0.0-nightly.164
. I found out that I was wrong, because changes are actually detected, rebuild happens, but it seems to be some kind of cache issue - when I use --no-cache
, then it starts working as expected. But downside of this "hotfix" is, that rebuild takes 10x more time than before.
still having the same issue on the last 1.x version
how is it possible that such a foundational bug that prevents anyone from building multi-page sites hasen't been solver in almost two years?
I also have this issue best work around for me was to load the css as string and append it to the html myself using
import cssString from βbundle-text:./styles.cssβ
You're getting this with Parcel 2 as well?
@micopc I am using 1.12.4 the latest stable. (just tried with v2 that has a temp problem "Name already registered with serializer") update2: does not work with NPM on v2 but does with yarn if this is any help
Doesn't solve the issue for me. If you have two simple documents pointing to one another, it will follow a.href and try to make sense of the other doc and fail.
ifβ¦
meodai.html links to home.html
or home.html links to meodai.html
it still produces unpredictable results with CSS and JS sometimes working and sometimes not. As soon as I have multiple files I start getting CSS error messages like "Uncaught SyntaxError: Unexpected token ':'.
Read this: #3008
One part of the issue might be connected with including inline style in html file/s.
Do not include any inline style in your html files!
Combining @maximelebreton solution and removing inline style elements solved my problems.
I am able to have multiple page setup with correctly included shared _css_ or _js_ files. For completeness here is my _package.json_ file, note that it does not require including the other pages (.html files) in any parcel script, it is enough to reference the page in a simple _href_ attribute, such as <a href="product.html">Product page</a>
. Referencing the home or index page back from the product page works as well.
{
"name": "my-app",
"version": "0.0.1",
"description": "super-duper",
"keywords": [
"fixed"
],
"scripts": {
"build": "parcel build index.html",
"dev": "parcel index.html --open",
"serve": "serve dist/",
"start": "npm run build && npm run dev",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"parcel-bundler": "^1.12.4",
"serve": "^11.3.2"
},
"dependencies": {
"aos": "^2.3.4"
}
}
My starting project is html5boilerplate
Most helpful comment
any news?
Temp solution:
src/shared.js
src/pages/about.js
src/pages/about.html
src/pages/index.js
src/pages/index.html