π bug report
π Configuration (.babelrc, package.json, cli command)
package.json
"scripts": {
"dev": "node build.js",
"build": "node build.js"
}
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();
src/index.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>Index.html</h1>
</body>
</html>
src/index2.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>
src/index.js
import './index.css'
src/index.css
body {
background-color: red;
}
π€ Expected Behavior
The same css file should be linked to both dist/index.html dist/index2.html
π― Current Behavior
dist/index.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>
<link rel="stylesheet" href="/src.e31bb0bc.css"></head>
<body>
<script src="/src.e31bb0bc.js"></script>
<h1>Index.html</h1>
</body>
</html>
dist/index2.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>
The css file is lined only to index.html and not to index2.html
π Your Environment
| Software |
Version(s) |
| Parcel |
1.10.3 |
| Node |
11.3.0 |
| npm/Yarn |
npm 6.4.1 |
| Operating System |
|
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?
any news?
Temp solution:
src/shared.js
src/pages/about.js
src/pages/about.html
src/pages/index.js
src/pages/index.html
Any updates?
If Iβm not mistaken, the current work around is to create an index for each entry point?
index-main.jsforindex.htmlindex-about.jsforabout.html@mischnic The original issue was reported more than a year ago. Any update so far?
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/*.htmllocalhost:1234/page1.html - has black body and css linked inside head tag localhost:1234/page2.html - has notThe current alpha version works as expected.
@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.)
As suggested here, I had to remove the
mainfield inpackage.jsonand runparcel build src/**/*.html, and then they should all build.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:
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.