JHipster-创建一个新的Angular前端环境

如何解决JHipster-创建一个新的Angular前端环境

我已经在NGnix服务器上部署了 JHipster (6.10.1)生成的Angular FrontEnd。 我想依靠某些特定的环境配置(dev,prod,staging等)来部署此FrontEnd。

我知道Angular可以通过使用/创建一些文件来自定义配置:

  • environment.dev.ts
  • environment.prod.ts
  • environment.staging.ts

并使用ng build --configuration=staging

我应该在{strong> package.json 文件中添加什么样的参数,以使用npm run build:<ENV>命令选择正确的环境?

关于...

更新08/09

感谢您,我想只使用您所描述的本机Angular解决方案。不幸的是,当我使用 JHipser 时,最好只是扩展已经存在的内容,而不是创建其他方式来部署其他环境。这意味着基于 webpack 最好有与现有解决方案相对应的解决方案。

尽管如此,angular.json文件中的所有必要修改(您已经描述过)已经完成。 我希望在 webpack.common.js webpack.prod.js 中有许多插件和加载器,这些插件和加载器在较低环境中部署时会用到。>

例如,在webpack.common.js中有种插件:

    plugins: [
        new webpack.DefinePlugin({
            'process.env': {            
                NODE_ENV: `'${options.env}'`,BUILD_TIMESTAMP: `'${new Date().getTime()}'`,// APP_VERSION is passed as an environment variable from the Gradle / Maven build tasks.
                VERSION: `'${process.env.hasOwnProperty('APP_VERSION') ? process.env.APP_VERSION : 'DEV'}'`,DEBUG_INFO_ENABLED: options.env === 'development',// The root URL for API calls,ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`.
                // If this URL is left empty (""),then it will be relative to the current context.
                // If you use an API server,in `prod` mode,you will need to enable CORS
                // (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations)
                SERVER_API_URL: `''`
            }

        }),new CopyWebpackPlugin([
            { from: './node_modules/swagger-ui-dist/*.{js,css,html,png}',to: 'swagger-ui',flatten: true,ignore: ['index.html'] },{ from: './node_modules/axios/dist/axios.min.js',to: 'swagger-ui' },{ from: './src/main/webapp/swagger-ui/',{ from: './src/main/webapp/content/',to: 'content' },{ from: './src/main/webapp/favicon.ico',to: 'favicon.ico' },{ from: './src/main/webapp/manifest.webapp',to: 'manifest.webapp' },// jhipster-needle-add-assets-to-webpack - JHipster will add/remove third-party resources in this array
            { from: './src/main/webapp/robots.txt',to: 'robots.txt' }
        ]),new HtmlWebpackPlugin({
            template: './src/main/webapp/index.html',chunks: ['polyfills','main','global'],chunksSortMode: 'manual',inject: 'body'
        }),new BaseHrefWebpackPlugin({ baseHref: '/' }),new AngularCompilerPlugin{
            mainPath: utils.root('src/main/webapp/app/app.main.ts'),tsConfigPath: utils.root('tsconfig.app.json'),sourceMap: true
        })
    ]

有趣的插件是 DefinePlugin AngularCompilerPlugin

要部署依赖于Webpack和某些特定配置的Angular应用程序,我想我需要加载从 environment。 .ts 文件中获取的一些变量,并将它们发送到 DefinePlugin ,它会提供 AngularCompilerPlugin 插件。

package.json 文件中包含脚本:

"scripts": {
    "prettier:format": "prettier --write \"{,src/**/}*.{md,json,ts,scss,yml}\"","lint": "eslint . --ext .js,.ts","lint:fix": "npm run lint -- --fix","ngc": "ngc -p tsconfig.app.json","cleanup": "rimraf target/classes/static/ target/classes/aot","clean-www": "rimraf target/classes/static/app/{src,target/}","start": "npm run webpack:dev","start-tls": "npm run webpack:dev -- --env.tls","serve": "npm run start","build": "npm run webpack:prod","test": "npm run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js","test:watch": "npm run test -- --watch","webpack:dev": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9060 --watch-content-base --env.stats=minimal","webpack:dev-verbose": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9060 --watch-content-base --profile --progress --env.stats=normal","webpack:build:main": "npm run webpack -- --config webpack/webpack.dev.js --env.stats=minimal","webpack:build": "npm run cleanup && npm run webpack:build:main","webpack:prod:main": "npm run webpack -- --config webpack/webpack.prod.js --profile","webpack:prod": "npm run cleanup && npm run webpack:prod:main && npm run clean-www","webpack:test": "npm run test","webpack-dev-server": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js","webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js"
  }

最后,问题很可能是: 我该如何通过以下命令传递参数:

npm run webpack:staging:main

使用暂存环境配置来部署应用程序吗?

弗雷德

解决方法

您可以通过在angular.json文件中添加适当的配置来实现。

在您的情况下,您可能想在角度示意图中添加一个新块,并添加以下内容:

          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts","with": "src/environments/environment.staging.ts"
            }
          ],

对于您的新环境,我建议根据您期望的行为,将其基于“生产”或“开发”模块。 通过以下方式传递参数时请小心:

npm run build -- --staging

关于package.json,我通常使用两个选项:outputPath和deleteOutputPath。第二个很好的方法是得到一个干净的目录。没必要,但是很方便:

"build:staging": "ng build --staging --outputPath=YourOutputPath --deleteOutputPath=true",

那样您就可以做到:

npm run build:staging

如果您想将SSR添加到您的项目中,这将花费更多的工作,尽管比那时容易得多。

完整文档可能会帮助=> https://angular.io/cli/build

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-