英文:
How do I use packages installed from npm in my Laravel app?
问题
我尝试安装了多个不同的包,但每次都失败了。假设我想将Wysimark编辑器添加到我的项目中。我按照文档中的描述运行npm i --save @wysimark/standalone
。接下来,在resources/js/app.js
中,我添加了这行代码:
import { createWysimark } from "@wysimark/standalone";
但接下来我该怎么做呢?当我尝试在我的Laravel视图中使用createWysimark()
函数时,出现了Uncaught ReferenceError: createWysimark is not defined
。我应该以某种方式将app.js
文件包含到页面中吗?但是怎么做呢?我不能使用它的路径,因为它在resources
文件夹中,对吗?
英文:
I have tried to install multiple different packages and I have failed every time. Let's say I want to add the Wysimark editor to my project. I run npm i --save @wysimark/standalone
as described in the documentation. Next, in resources/js/app.js
, I add this line:
import { createWysimark } from "@wysimark/standalone";
But what do I do next? When I try to use the createWysimark()
function in my Laravel view, I get Uncaught ReferenceError: createWysimark is not defined
. Should I include the app.js
file into the page somehow? But how? I can't use its path, since it is in the resources
folder, right?
答案1
得分: 0
你必须在导入资产后实际构建它们。查看你根文件夹内的 package.json。对于开发,通常是 npm run development
,但可能会根据你的 package.json 而有所不同。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论