【发布时间】:2019-09-06 22:24:40
【问题描述】:
我想将editor.md markdown editor 包含在一个纤细的组件中。 我已经尝试设置它,但我什么也没得到:没有来自 javascript 的堆栈跟踪,也没有任何关于问题应该是什么的线索。
我包括手头问题的主要相关文件。
rollup.config.js:
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import globals from 'rollup-plugin-node-globals';
import builtins from 'rollup-plugin-node-builtins';
import { terser } from 'rollup-plugin-terser';
const production = !process.env.ROLLUP_WATCH;
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/bundle.js'
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file — better for performance
css: css => {
css.write('public/bundle.css');
}
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration —
// consult the documentation for details:
// https://github.com/rollup/rollup-plugin-commonjs
resolve({
browser: true,
preferBuiltins: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
globals({
dirname: false,
filename: false,
baseDir: false
}),
builtins(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};
src/App.svelte:
<script>
import { onMount } from 'svelte';
import jQuery from 'jquery';
import editormd from 'editor.md/editormd';
export let content = "# Edit!";
onMount(() => {
window.jQuery = jQuery;
var editor = editormd("editor", {
width: "90%",
height: 640,
autoLoadModules: false,
});
});
</script>
<style>
@import "editor.md/css/editormd.css";
</style>
<div id="editor">
<textarea bind:value={content}/>
</div>
package.json:
{
"name": "svelte-app",
"version": "1.0.0",
"devDependencies": {
"npm-run-all": "^4.1.5",
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-inject": "^3.0.1",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^4.0.4",
"svelte": "^3.0.0"
},
"dependencies": {
"editor.md": "^1.5.0",
"jquery": "^3.4.1",
"sirv-cli": "^0.4.4"
},
"scripts": {
"build": "rollup -c",
"autobuild": "rollup -c -w",
"dev": "run-p start:dev autobuild",
"start": "sirv public --single",
"start:dev": "sirv public --single --dev"
}
}
我希望编辑器能够加载,但结果我只显示了原始文本区域。 在开发人员控制台中,我什么也没显示。 我是一个使用汇总配置和插件的新手,所以我想我搞砸了这些,但不明白它们有什么问题。
【问题讨论】: