I'm having an issue with vue's build settings and Flask's static_folder setting. I've tried several cases with Flask's static_folder setting, but the only one case among these three worked for me. And I can't see why.
// Build setting from vue.config.js
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/dist/'
: '/'
}
So my index.html has asset files' src and href as:
<script src=/dist/js/app.f4f6d455.js></script>
Here are my trials and results.
Case 1: Error!
// Flask Setting
app = Flask(__name__, template_folder = "./dist")
//Directory Structure
/project
/dist
/js
app.f4f6d455.js
index.html
flask.py
result: Failed to load resource > http://127.0.0.1:5000/dist/js/app.f4f6d455.js
Case 2: Error!
Copied assets into 'static/dist' since flask's default static_folder is 'static', and left dist folder intact to better clarify the error message.
// Flask Setting
app = Flask(__name__,
template_folder = "./dist")
//Directory Structure
/project
/dist
/js
app.f4f6d455.js
index.html
/static
/dist
/js
app.f4f6d455.js
flask.py
result: Failed to load resource > http://127.0.0.1:5000/dist/js/app.f4f6d455.js
Case 3: Works!
Changed flask's static_folder to 'dist'
// Flask Setting
app = Flask(__name__,
static_folder = "dist",
template_folder = "./dist")
//Directory Structure
/project
/dist
/js
app.f4f6d455.js
index.html
flask.py
I assumed that it was the matter of the root path when Flask tries to find its asset files. But Case 3 worked when case 2 didn't. if the root path of case 2 were 'http://127.0.0.1:5000/static', then it should have worked. Could anyone help me to understand this?
Thanks in advance.
publicPath
andoutputDir
. What URL path should be used to load the default page of your app?http://localhost:5000/
orhttp://localhost:5000/dist/
? – Phil