简体   繁体   English

Babel 和 next.js - 如何在项目中构建、babel 和附加我自己的脚本

[英]Babel and next.js - how build, babel and attach my own script in project

I am newbie with next.js and I struggle with some rather normal use case, but I failed.我是 next.js 的新手,我在一些相当正常的用例中挣扎,但我失败了。

I have my own js lib which is ES6, I need it convert it to babel and use in my next.js app.我有自己的 js 库,它是 ES6,我需要将它转换为 babel 并在我的 next.js 应用程序中使用。

How can i do this?我怎样才能做到这一点? Where in this framework can i configure babel for specific files and how to attach it?在这个框架中,我可以在哪里为特定文件配置 babel 以及如何附加它?

At this moment i did it manually I put my files into /static/js/mylib.js and I attached it in my component like this:此时我手动完成了我将文件放入 /static/js/mylib.js 并将其附加到我的组件中,如下所示:

But I would like to babel my file during the build and then use that file from /build/static folder.但是我想在构建过程中 babel 我的文件,然后使用 /build/static 文件夹中的文件。

How can I achieve it?我怎样才能实现它?

Next.js, just like the create-react-app framework has made a selection of build-scripts and compilers for you, and hidden them so you don't have to worry about this stuff. Next.js,就像 create-react-app 框架为你选择了构建脚本和编译器一样,并且隐藏了它们,所以你不必担心这些东西。 You can customise a lot of it, here's the resource for that: https://nextjs.org/docs#custom-configuration你可以自定义很多,这里是资源: https : //nextjs.org/docs#custom-configuration

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

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