I am building react seed project with the structure like this:
project
│ package.json
│ webpack.config.js
│ .babelrc
│
└───bin
│ app.bundle.js
│
└───node_modules
|
└───public
│ index.html
└───src
app.jsx
To start the project i have setup command npm run dev which runs:
webpack -d --watch && ./node_modules/.bin/http-server -a localhost -p 8000 -c-1
It starts the server on localhost:8000 and webpack is watching for changes.
http-server
has an entry point in ./public folder where my index.html is.
This seems to be a secure way of running server because it only have access to public folder, but then i ran into a problem when i try to include my compiled app.bundle.js
file.
./public/index.html
<html>
<head>
<meta charset="utf-8">
<title>Seed project</title>
</head>
<body>
<div id="app" />
<script src="../bin/app.bundle.js" type="text/javascript"></script>
</body>
</html>
When i run the server i get the error that the app.bundle.js file is not found, because the server can't see anything that is over the entry point which is public folder.
Moving index.html to the root folder is not a good practice, because then it will be possible to access all the other files, which is not secure.
How should this issue be solved ?
Thanks in advance.
PS. Webpack compiles files from the src folder and creates single file in ./bin folder.
via Giedrius
No comments:
Post a Comment