简体   繁体   English

如何在Webpack中更改请求路径

[英]How to change the request path in webpack

Im trying to integrate PhotoSwipe into my current Project 我正在尝试将PhotoSwipe集成到我当前的项目中

this is the webpack.config.js 这是webpack.config.js

module.exports =
{
    entry: './input.js',
    output:
    {
        path: 'js/',
        filename: 'output.js'
    },
    resolve:
    {
        alias:
        {
            'photoswipe_js': './node_modules/photoswipe/dist/photoswipe.js',
            'photoswipe_ui_default': './node_modules/photoswipe/dist/photoswipe-ui-default.js'
        }
    },
    watch: true
};

this is my main file 这是我的主文件

require(['photoswipe_js', 'photoswipe_ui_default'], function( PhotoSwipe, PhotoSwipeUI_Default )
{
    console.log(PhotoSwipe);
    console.log(PhotoSwipeUI_Default);
});

在此处输入图片说明

for some reason its trying to find the compiled file from the project root like 由于某种原因,它试图从项目根目录中找到已编译的文件,例如

'/1.output.js'

I need it to try to fetch the output file from 我需要它来尝试从中获取输出文件

'/bundles/mybundle/js/1.output.js'

instead, how can I do that? 相反,我该怎么做?

Add publicPath to your output object : publicPath添加到您的输出对象:

module.exports =
{
  ...
  output:
  {
    path: 'js/',
    filename: 'output.js',
    publicPath: '/bundles/mybundle/js/'
  },
  ...
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM