首先声明一下,我不是很熟悉Webpack,所以这可能是个琐碎的问题。
我正在尝试通过monaco-editor-webpack-plugin
在Laravel项目中使用Monaco。由于该插件需要修改webpack.config.js
,而Laravel使用webpack.mix.js
,通过摸索,我成功地得到了以下配置:
/* eslint-disable import/no-extraneous-dependencies */
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/scss/app.scss', 'public/css')
.webpackConfig({
plugins: [
new MonacoWebpackPlugin({
languages: ['css', 'html', 'javascript', 'json', 'scss', 'typescript'],
}),
],
});
目前一切运作良好,文件已经编译,编辑器也正常工作。但是我遇到的问题是编辑器编译后的文件被生成在/public
目录下,例如:/public/editor.worker.js
, /public/0.js
等。
我真的想避免这种情况,而是希望这些文件编译到/public/js/vendor/monaco
目录中。我尝试将output
配置更改为/public/js/vendor/monaco
,但它会将所有内容(包括CSS、字体等)都编译进该目录。
有没有办法说“嘿,我想要将这些 Monaco 文件放在这里,同时让其他所有文件保持原状?”
publicPath
怎么样? - apokryfosextract
命令将代码移动到vendor.js
中。注意: 如果需要更多信息,可以在此处查看 https://laravel.com/docs/8.x/mix#vendor-extraction。 - Chandan