subdirectory filename with dynamic imports loads incorrect URL
Description
html-webpack-plugin is capable of handling filename within a sub-directory. However, the default dynamic import seems to be breaking when using it in combination with subdirectory filename. I have tried setting up publicPath and output path, but such settings affect the path of all chunks. I have reproduced the issue with a minimal project below:
Error Message & Stack Trace
root loaded
Failed to load resource: the server responded with a status of 404 (Not Found)
Refused to execute script from 'http://127.0.0.1:8080/example/0.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Uncaught (in promise) Error: Loading chunk 0 failed.
(error: http://127.0.0.1:8080/example/0.js)
at HTMLScriptElement.onScriptComplete (main.js:109)
Config
const HTMLWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
plugins: [
new HTMLWebpackPlugin({
filename: 'example/index.html',
})
]
}
src/index.js
console.log('root loaded');
import('./part2.js').then((v) => {
console.log(v);
});
src/part2.js
console.log('part2 loaded');
Generated
File structure
dist
├── 0.js
├── example
│ └── index.html
└── main.js
HTML file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webpack App</title>
</head>
<body>
<script type="text/javascript" src="../main.js"></script></body>
</html>
Relevant Links
minimal reproduction on Github
Environment
➜ webpack-path-test git:(master) node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
npm --version
npm ls webpack
npm ls html-webpack-plugin
Node.js v9.5.0
linux 4.10.17-041017-generic
5.8.0
/home/vibhav/node-projects/webpack-path-test
└── [email protected]
/home/vibhav/node-projects/webpack-path-test
└── [email protected]
Thanks @vibhavsinha
Correct me if I am wrong but the dynamic important is done by webpack.
So I guess the html-webpack-plugin can't help here.
@vibhavsinha I also met this problem, have you solved it?
setting the public path to / should allow you to download dynamic files correctly
webpackConfig.output.publicPath = '/'
Note: folders. There are no folders to do as you do is ok. very sad
Closed as unrelated to this plugin