如何在我的Laravel应用程序中使用从npm安装的包?

huangapple go评论58阅读模式
英文:

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 而有所不同。

英文:

You have to actually build your assets after importing them. Take a look into your package.json inside your root folder. For development it's usually npm run development but may differ depending on your package.json

如何在我的Laravel应用程序中使用从npm安装的包?

huangapple
  • 本文由 发表于 2023年7月11日 14:48:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76659324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定