在使用 Webpack 的情況下嘗試使用
我是否忘記了加載 codicons 的內容?
您可以通過以下方式重現此問題:https ://github.com/yoichiro/monaco-editor-test/tree/main
索引.html
<!doctype html>
<html lang="en">
<head>
<style>
.source-editor {
width: 640px;
height: 320px;
}
</style>
</head>
<body>
<div class="source-editor"></div>
</body>
</html>
索引.ts
import * as monaco from 'monaco-editor';
window.addEventListener('load', () => {
monaco.editor.create(document.querySelector('.source-editor'));
});
webpack.config.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = {
mode: 'development',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
clean: true,
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
},
{
test: /\.scss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'expanded',
},
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.ttf$/,
use: ['file-loader'],
},
],
},
resolve: {
extensions: ['.ts', '.js', 'scss', 'html'],
},
plugins: [
new MonacoEditorWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
devtool: 'source-map',
watchOptions: {
ignored: /node_modules/,
},
devServer: {
static: './build',
// open: true,
watchFiles: ['src/**/*'],
},
};
uj5u.com熱心網友回復:
從 Webpack 5 開始,我們需要使用Asset Modules而不是 loader。
也就是說,以下代碼適用于 Webpack 5:
{
test: /\.ttf$/,
type: 'asset/resource'
}
如果使用 Webpack 4 及更低版本,以下代碼將起作用:
{
test: /\.ttf$/,
use: ['file-loader']
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/454935.html
標籤:javascript 网页包 摩纳哥编辑
