简体   繁体   English

如何在Laravel中使用npm正确引用新安装的软件包的路径?

[英]How to properly reference the path with newly installed packages using npm in Laravel?

I've installed ReactJS and Babel using npm in my laravel project. 我已经在laravel项目中使用npm安装了ReactJS和Babel。 They are found in "node_modules" folder created by npm itself. 它们位于npm本身创建的“ node_modules”文件夹中。 But the problem is my react code doesn't seem to work if I import using this code: 但是问题是,如果我使用以下代码导入,我的反应代码似乎不起作用:

<script src="node_modules/react/react.js"></script>
<script src="node_modules/react-dom/dist/react-dom.js"></script>
<script src="node_modules/babel-core/lib/api/browser.js"></script>

Is the format of the path correct? 路径格式是否正确? because if I just import using this type of code for all my imports required for ReactJS: 因为如果我只是使用此类型的代码来导入ReactJS所需的所有导入,则:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>

It seems to work if I just use the internet for getting the packages. 如果我只是使用互联网来获取软件包,那似乎可行。

My react code is here: 我的反应代码在这里:

<div id="myapp"></div>
<!-- JavaScripts -->
<script type="text/babel">
    var BuckyComponent = React.createClass({
        render: function()  {
            return(
                <h2>{this.props.user} likes to eat {this.props.food}</h2>
            );
        }
    });

    React.render(
        <div>
            <BuckyComponent user="Arth" food="Bacon"/>
            <BuckyComponent user="Arth" food="Pork"/>
            <BuckyComponent user="Arth" food="Chicken"/>
        </div>,
        document.getElementById('myapp')
    );
</script>

That's not the way you use Npm/Bower packages within Laravel. 那不是您在Laravel中使用Npm / Bower软件包的方式。 Either package manager will store its files outside the Laravel public folder, the first inside node_modules and the later inside bower_components . 无论是包管理器将存储其Laravel 公共文件夹以外的文件中,第一室内node_modules和后内bower_components So they're not intended to be publicly available. 因此,它们不打算公开提供。

So how would you use their packages within Laravel? 那么您将如何在Laravel中使用它们的软件包? Using build systems like Laravel Elixir , just the Gulp or even the Grunt . 使用Laravel Elixir之类的构建系统,仅使用Gulp甚至Grunt

It's all up to you to copy the distribution files of React and Babel, concat them, minify them and the like. 复制和分发 React和Babel的分发文件,合并它们,缩小它们等等,完全取决于您。 You'll end up with them inside the public folder, but before you'll want to do a nice concatenation and minification of all that stuff to serve the smallest possible number of files and their sizes. 你会与他们结束了在公共文件夹内,但在此之前,你会想要做的所有的东西一个很好的串联和缩小服务文件及其大小的最小数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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