如果您想了解使用webpack构建angular2应用程序–找不到./compiler.es5.ts和angularwebpack配置的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用webpa
如果您想了解使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts和angular webpack配置的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts的各个方面,并为您解答angular webpack配置的疑在这篇文章中,我们将为您介绍使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts的相关知识,同时也会详细的解释angular webpack配置的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- 使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts(angular webpack配置)
- angular – 使用webpack从bundle中排除ts / js文件
- angular – 使用Webpack时出错
- angular – 在angluar2 webpack中使用Font-awesome
- Angular2应用程序的configuration – nginx和docker
使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts(angular webpack配置)
WARNING in ./~/@angular/compiler/@angular/compiler.es5.js Cannot find source file 'compiler.es5.ts': Error: Can't resolve './compiler.es5.ts' in '../node_modules\@angular\compiler\@angular' @ ./~/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic.es5.js 11:0-72
消息是正确的,因为在该位置没有这样的带有ts扩展名的文件,该文件存在但具有js扩展名.
我是否错过了webpack配置值?
顺便说一句:如果我使用@ angular / cli v1.0构建应用程序,我看不到警告.
https://github.com/angular-redux/store/issues/64
解决方法是在webpack.config.js中为source-map-loader添加排除规则.
{ test: /\.(js|ts)$/,exclude: [ // workaround for this issue path.join(__dirname,'node_modules','@angular/compiler') ],use: [{ loader: 'source-map-loader' }],enforce: 'pre' }
但上面的解决方案只不过是暂时的.
angular – 使用webpack从bundle中排除ts / js文件
下面是两个文件的代码.
settings.ts
const foo = { url:'localhost' }; export { foo };
script.ts
import { foo } from 'settings';
两个ts文件将在bundle之前编译为js文件.现在我想从bundle中排除settings.ts文件,并希望在dist文件夹中分别复制setting.ts文件.
下面是webpack.config文件
loaders: [ { test: /\.ts$/,loaders: ['awesome-typescript-loader','angular2-template-loader'],exclude: [/\settings.ts$/] },]
我发现这没有运气.
我可以使用copyWebpackPlugin复制dist文件夹中的settings.js文件.但无法从捆绑中排除settings.ts文件.
下面是文件夹结构的屏幕截图. Webpack.config与src文件夹位于同一级别
解决方法
exclude: [ path.resolve(__dirname,'/settings.ts'),]
正如this GitHub issue所建议的那样.
angular – 使用Webpack时出错
当我跑下午开始时,我得到70个错误,如下所示.
$npm start > angular2-webpack@1.0.0 start /Users/angular-webpak [at-loader] Using typescript@2.0.10 from typescript and "tsconfig.json" from /Users/angular-webpak/src/tsconfig.json. [at-loader] Checking finished with 70 errors ... ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:52 TS1005: '=' expected. ERROR in [at-loader] node_modules/@angular/common/src/directives/ng_class.d.ts:48:34 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/common/src/pipes/async_pipe.d.ts:44:38 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler.d.ts:32:38 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler.d.ts:44:32 TS2304: Cannot find name 'Map'. ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler_host.d.ts:20:33 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:342:20 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:344:28 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:346:15 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:348:23 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:350:17 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/compile_Metadata.d.ts:352:25 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/directive_normalizer.d.ts:38:72 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/directive_normalizer.d.ts:40:74 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/i18n/extractor.d.ts:14:33 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/i18n/extractor.d.ts:22:35 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/jit/compiler.d.ts:44:49 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/jit/compiler.d.ts:46:65 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/Metadata_resolver.d.ts:58:104 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/output/output_ast.d.ts:433:63 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/compiler/src/resource_loader.d.ts:13:23 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/util.d.ts:33:18 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/compiler/src/util.d.ts:34:46 TS2304: Cannot find name 'Promise'. <snipped several similar errors> ERROR in [at-loader] node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:24:15 TS2304: Cannot find name 'Map'. ERROR in [at-loader] node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:28:16 TS2304: Cannot find name 'Map'. <snipped several similar errors> ERROR in [at-loader] node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts:11:30 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts:22:30 TS2304: Cannot find name 'Set'. ERROR in [at-loader] node_modules/@angular/router/src/config.d.ts:307:85 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:78:99 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:157:109 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:227:115 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:297:89 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:367:50 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/router.d.ts:392:70 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/router.d.ts:414:59 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@angular/router/src/utils/collection.d.ts:36:79 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:38 TS2371: A parameter initializer is only allowed in a function or constructor implementation. ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:46 TS2304: Cannot find name 'keyof'. ERROR in [at-loader] node_modules/rxjs/Observable.d.ts:68:60 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/Observable.d.ts:68:70 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/observable/PromiSEObservable.d.ts:40:31 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/observable/PromiSEObservable.d.ts:41:26 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:2:60 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:3:79 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:3:89 TS2304: Cannot find name 'Promise'. ERROR in [at-loader] src/app/app.component.ts:8:14 TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. ERROR in [at-loader] src/app/app.module.ts:13:14 TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. Child html-webpack-plugin for "index.html": chunk {0} index.html 299 bytes [entry] [rendered] Child extract-text-webpack-plugin: chunk {0} extract-text-webpack-plugin-output-filename 1.95 kB [entry] [rendered] webpack: Failed to compile.
你必须修改webpack.common.js
angular – 在angluar2 webpack中使用Font-awesome
更新了我的webpack.config.js以包含加载字体文件:
module: { loaders: [ { test: /\.ts$/,loader: 'awesome-typescript-loader' },{ test: /\.json$/,loader: 'json-loader' },{ test: /\.html/,loader: 'raw-loader' },{ test: /\.css$/,loader: 'to-string-loader!css-loader' },// For font-awesome {test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,loader: 'file?name=fonts/[name].[hash].[ext]?'} ]
},
使用以下命令安装font-awesome:
npm install font-awesome
添加了对ts文件的要求
要求(” ../ node_modules /字体真棒/ CSS /字体awesome.css’);
我一直在收到这个错误:
ERROR in ./~/font-awesome/css/font-awesome.css
Module build Failed: Error: Cannot find module ‘../fonts/fontawesome-webfont.eot?v=4.6.3’
任何想法如何解决这一问题 ?.
解决方法
{ test: /\.css$/,loader: 'style!css' },
Angular2应用程序的configuration – nginx和docker
我有一个REST后端服务位于一些服务器和前端应用程序的angular度。 我正在使用Angular CLI来构build应用程序。 我的后端服务器的位置位于环境文件中。 我的应用程序的要求是,我提供了两个docker图像。 一个与我的后端服务器(Java的春季启动应用程序)和第二个是与ng build myApp命令的静态HTML生成。 然后,我将内容od dist目录复制到docker映像上的相应目录中,如此处所示的Nginx docker映像 。
问题是,后端和前端可能在不同的服务器上工作。 有什么办法可以configuration我的前端应用程序,我可以更改后端服务器的位置,每个容器的开始?
在Windows上与Docker联网
WidNows上的Postgresql泊坞窗容器
Nginx作为docker上游代理与地图
在Docker Container中运行命令
运行泊坞窗容器上的错误500
我知道这是一个古老的问题,但是我面对同样的问题,花了一段时间才解决。 这可以帮助那些来自搜索引擎的人。
我找到了两个解决方案(我选择了第二个)。 两者都允许您在docker中使用环境变量来配置您的API URL。
解决方案1(“客户端”):env.js asset + sed
这个想法是让你的Angular客户端从你的HTTP服务器加载一个env.js文件。 这个env.js将包含API URL,并且在你的容器启动时将会被修改。 这是你在问题评论中讨论的内容。
在角度应用资源文件夹中添加一个env.js (angular-cli的src/assets ):
var MY_APP_ENV = { apiUrl: 'http://localhost:9400',}
在你的index.html ,你将加载你的env:
<head> <Meta charset="utf-8"> <base href="/"> <script src="env.js"></script> </head>
在你的environment.ts中,你可以使用这个变量:
declare var MY_APP_ENV: any; export const environment = { production: false,apiUrl: MY_APP_ENV.apiUrl };
在你的Nginx Dockerfile中:
FROM Nginx:1.11-alpine copY tmp/dist /usr/share/Nginx/html copY run.sh /run.sh CMD ["sh","/run.sh"]
run.sh脚本是sed魔法发生的地方:
#!/bin/sh # API /bin/sed -i "s|http://localhost:9400|${MY_API_URL}|" /usr/share/Nginx/html/env.js Nginx -g 'daemon off;'
在您的角度服务中,使用environment.apiUrl连接到API(您需要导入环境,请参阅Angular 2文档)。
解决方案2(纯服务器端):Nginx代理配置+ envsubst
我对之前的解决方案不满意,因为API URL需要从主机的角度来看,它不能在我的docker-compose设置中使用另一个容器主机名。
所以我想:很多人使用Nginx作为代理服务器,为什么不用这种方式代理/api到我的其他容器。
Dockerfile:
FROM Nginx:1.11-alpine copY tmp/dist /usr/share/Nginx/html copY frontend.conf.template /etc/Nginx/conf.d/frontend.conf.template copY run.sh /run.sh CMD ["/bin/sh","/run.sh"]
frontend.conf.template:
server { listen 80; server_name myserver; # API server location /api/ { proxy_pass ${MY_API_URL}/; } # Main location / { root /usr/share/Nginx/html; index index.html index.htm; try_files $uri$args $uri$args/ /index.html; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/Nginx/html; } }
run.sh:
#!/bin/sh # Substitute env vars envsubst '$MY_API_URL' < /etc/Nginx/conf.d/frontend.conf.template > /etc/Nginx/conf.d/default.conf # Start server Nginx -g 'daemon off;'
envsubt允许你用一个类似shell的语法来替换字符串中的环境变量。
然后使用/api/xyz从Angular应用程序连接到API。
我认为第二个解决方案更清洁。 API URL可以是docker-compose设置中的API docker容器名称,这很好。 客户端不参与,它是透明的。 但是,这取决于Nginx。
我们今天的关于使用webpack构建angular2应用程序 – 找不到./compiler.es5.ts和angular webpack配置的分享就到这里,谢谢您的阅读,如果想了解更多关于angular – 使用webpack从bundle中排除ts / js文件、angular – 使用Webpack时出错、angular – 在angluar2 webpack中使用Font-awesome、Angular2应用程序的configuration – nginx和docker的相关信息,可以在本站进行搜索。
本文标签: