我正在使用Webpack 2的自動代碼分割將我的應用程序分成多個輸出文件。我webpack.config.js
文件是:如何配置webpack的自動代碼拆分以相對於構建輸出文件夾加載模塊?
const path = require('path');
module.exports = {
entry: './app.js',
output: {
filename: '[name].js',
path: path.join(__dirname, 'build'),
}
}
此建立正確我app.js
文件到文件夾build
與其他模塊文件一起。構建目錄有以下文件:
main.js
0.js
我的問題是,當main.js
請求0.js
,它在我的應用程序的根這樣做,而不是相對於當前位置。因此,它應該加載localhost:8000/build/0.js
時基本上試圖加載localhost:8000/0.js
。我怎樣才能配置我的項目,以便我的項目正確加載拆分模塊相對於我的主入口點的路徑?
這很好。對於替代document.currentScript的IE,我建議使用'document.querySelector('script [src $ =「nameofmyapp.js」]')。src' – undefinederror