Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 网页包url加载程序动态公共路径_Webpack_Urlloader - Fatal编程技术网

Webpack 网页包url加载程序动态公共路径

Webpack 网页包url加载程序动态公共路径,webpack,urlloader,Webpack,Urlloader,我正在使用webpack的url加载器插件,并将其配置如下: module.exports = { entry: './src/admin.planningview.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), publicPath: 'http://poc.local/dist/' }, module: {

我正在使用webpack的url加载器插件,并将其配置如下:

module.exports = {
    entry: './src/admin.planningview.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: 'http://poc.local/dist/'
    },
    module: {
        rules: [
            {
                test: /\.(png|woff|woff2|eot|ttf|svg)$/,
                loader: 'url-loader?limit=100000'
            }
        ]
    }
};
在my base.css中有以下行:

@font-face {
    font-family: 'open_sansregular';
    src: url('fonts/opensans-regular-webfont.eot');
    src: url('fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'), url('fonts/opensans-regular-webfont.woff') format('woff'), url('fonts/opensans-regular-webfont.ttf') format('truetype'), url('fonts/opensans-regular-webfont.svg#open_sansregular') format('svg');
    font-weight: normal;
    font-style: normal;
}
此文件位于子文件夹“字体”中

我的dist文件夹如下所示:

现在,我尝试基于块和资产的动态publicPath变量(因此覆盖url)加载所有这些文件

我添加了这是我的入口点文件:

__webpack_public_path__ = window.cdnURL;
window.cdnURL包含如下内容:

现在我的问题是块被正确加载,但是字体/woff文件没有。。我想这似乎是url加载器的问题

当我在调试模式下检查bundle.js时,我看到以下内容,它是旧的URL:


有什么想法吗?

使用css加载程序别名选项:

据我所知,
文件加载器(url加载器的回退)将在构建时对路径进行字符串化

要使用动态数据,您需要使用:

module.exports={
模块:{
规则:[
{
测试:/\(png | jpg | gif)$/i,
加载器:“文件加载器”,
选项:{
publicPath:“/some/path/”,
//添加以下内容。这可能会删除/替换“http://poc.local/dist/"
//您必须以字符串形式编写JS代码。
postTransformPublicPath:(p)=>`uuuuuuWebpack\uPublic\uuuuuuPath+${p}`,
},
},
],
},
};

不再受支持。他们建议改用webpack。