Ric*_*her 1 maven node.js npm reactjs yarnpkg
我在尝试从项目中的 npm 切换到纱线时遇到问题。我尝试下载yarn,但仍然使用npm来启动我的项目。我需要切换,因为我正在处理的一个项目需要它是纱线,所以我可以添加一个 maven 前端插件来将我的后端和前端联系起来以进行部署。
1.
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
<node.version>v10.13.0</node.version>
<yarn.version>v1.12.1</yarn.version>
2.
<profiles>
<profile>
<id>demo</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<workingDirectory>src/js</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>yarn test</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>test</arguments>
<environmentVariables>
<CI>true</CI>
</environmentVariables>
</configuration>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>compile</phase>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>src/js/build</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
链接1 https://github.com/amigoscode/spring-boot-react-fullstack/blob/app-0/course-files/profiles.txt 链路2 https://github.com/eirslett/frontend-maven-plugin
Seb*_*ráč 43
完整简单的分步答案:
npm i -g yarnyarn命令yarn.lock文件,现在删除package-lock.json * Notepackage.json文件中替换"scripts"所有npm命令yarn ** Noteyarn dev或任何用于运行纱线脚本的命令=> 完成* Note:重要的是你不要在yarn命令之前删除它(正如有些人建议的那样)它可能会破坏东西,例如你的yarn命令甚至无法工作并且会抛出错误:
Error: ENOENT: no such file or directory, open './package-lock.json'
Run Code Online (Sandbox Code Playgroud)
** Note:如果你用过
"preinstall": "npx npm-force-resolutions",
Run Code Online (Sandbox Code Playgroud)
您可以将其删除,默认情况下纱线正在使用,"resolutions"无需用力:)
| 归档时间: |
|
| 查看次数: |
5437 次 |
| 最近记录: |