简体   繁体   中英

requiring packages with JS instead of the asset pipeline - Rails

I'm trying to use a plugin called simplemde I used bower to bring in the plug in. The javascript it imported is trying to require other addons but when I try to run the code I get this error in the console Uncaught ReferenceError: require is not defined . I understand the you cannot require from the client side unless you make changes to the asset pipeline. I'm trying to find out what to do in this situation with a rails app.

JS

var CodeMirror = require("codemirror");
require("codemirror/addon/edit/continuelist.js");
require("./codemirror/tablist");
require("codemirror/addon/display/fullscreen.js");
require("codemirror/mode/markdown/markdown.js");
require("codemirror/addon/mode/overlay.js");
require("codemirror/addon/display/placeholder.js");
require("codemirror/addon/selection/mark-selection.js");
require("codemirror/mode/gfm/gfm.js");
require("codemirror/mode/xml/xml.js");

What are some ways I can get this file to work with Rails?

I bet you use files from the src directory of the SimpleMDE plugin. This files should be preprocessed and assembled into one on the server side before delivering to the client. You can use minified and assembled files from the dist directory. If you want to use source files anyway, you should tune your asset pipeline, for example like in article Bring CommonJS to your asset pipeline or use other tools, like Grunt or Gulp, for assets assembling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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