Laravel-mix Webpack 公共路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48862993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:25:00  来源:igfitidea点击:

Laravel-mix Webpack Public Path

laravelwebpackvue.jsvuejs2laravel-mix

提问by skribe

So I am using Laravel-Mix and have set up code splitting in Webpack. I am using a dynamic import for my Vue components like this.

所以我使用 Laravel-Mix 并在 Webpack 中设置了代码拆分。我正在为这样的 Vue 组件使用动态导入。

Vue.component('UserMenu', () => import('./components/UserMenu.vue'));

Since I am also using Babel, I have the syntax-dynamic-import plugin loading from my .babelrcfile in the project root.

由于我也在使用 Babel,因此我从.babelrc项目根目录中的文件中加载了语法动态导入插件。

This is all working fine, and Webpack is properly splitting the code on build. However, the problem is, it is putting the chunks in the public root rather than in public/js

这一切正常,并且 Webpack 在构建时正确拆分代码。然而,问题是,它将块放在公共根中而不是放在public/js

If in my webpack.mix.js I do...

如果在我的 webpack.mix.js 中我做...

mix.js('resources/assets/js/app.js', 'public/js');

...then the mix properly places the built file in the /jsdirectory.

...然后混合正确地将构建的文件放在/js目录中。

But in order to chunk the files, if in webpack.mix.js I do...

但是为了对文件进行分块,如果在 webpack.mix.js 中我做...

 mix.webpackConfig({
    entry: {
        app: './resources/assets/js/app.js',
    },
    output: {
        filename: '[name].js',
        publicPath: 'public/js',
    }
});

...all the chunks get put in the public root no matter what I assign to the publicPath property.

...无论我分配给 publicPath 属性的内容是什么,所有块都被放入公共根目录中。

Any idea what am I missing here?

知道我在这里缺少什么吗?

采纳答案by Serak Shiferaw

just change the chunk path in webpack.mix.jsunder your laravel root folder,

只需更改webpack.mix.jsLaravel 根文件夹下的块路径,

mix.webpackConfig({
    output: {
        filename:'js/main/[name].js',
        chunkFilename: 'js/chunks/[name].js',
    },
});

also note that the laravel way of changing main js location is using mix.js function

另请注意,更改主要 js 位置的 Laravel 方式是使用 mix.js 函数

mix.js('resources/assets/js/app.js', 'public/js/main')

回答by IvanBernatovic

Try to set public path using mix.setPublicPath('public/build')method.

尝试使用mix.setPublicPath('public/build')方法设置公共路径。