Answer the question
In order to leave comments, you need to log in
How to setup __webpack_public_path__ function at runtime?
I'm trying to set up a dynamic path for the build, the files are part of the wp plugin and the link to the exact directory is not known
in webpack, I read that you can specify __webpack_public_path__ in runtime, but I can't set it up correctly
//что то подобное, но не работает
var __webpack_public_path__ = window.__webpack_public_path__;
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
//publicPath: __dirname + '/',
//publicPath: '/',
//publicPath: path.join(__dirname, '/'),
publicPath: __webpack_public_path__ ,
chunkFilename: '[name].bundle.js'
},
Answer the question
In order to leave comments, you need to log in
I solve it like this (at the beginning of the entry file):
var src = document.querySelector('[src*="bundle"]').getAttribute("src");
__webpack_public_path__ = src.substr(0, src.lastIndexOf("/") + 1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question