[英]failing to delete of files, after AoT build
When i run the build:prod command from my package.json file, the compilation builds succesfully, but fails to delete .ngsummary.json files aswell as all .ngfactory.ts files当我从 package.json 文件运行 build:prod 命令时,编译成功构建,但无法删除 .ngsummary.json 文件以及所有 .ngfactory.ts 文件
The package.json file: package.json 文件:
{
"name": "name",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"build": "del-cli public/js/app && webpack --config webpack.config.dev.js --progress --profile --watch",
"build:prod": "del-cli public/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'public/js/app/**/*.js' 'public/js/app/**/*.js.map' '!public/js/app/bundle.js' '!public/js/app/*.chunk.js' 'assets/app/**/*.*.ngfactory.ts' 'assets/app/**/*.shim.ts' 'assets/app/**/*.ngsummary.json' 'assets/app/**/*.ngstyle.ts'"
},
"dependencies": {
"@angular/animations": "^4.4.3",
"@angular/cdk": "github:angular/cdk-builds",
"@angular/cli": "^1.4.2",
"@angular/common": "^4.4.3",
"@angular/compiler": "^4.4.3",
"@angular/compiler-cli": "^4.4.3",
"@angular/core": "^4.4.3",
"@angular/forms": "^4.4.3",
"@angular/http": "^4.4.3",
"@angular/platform-browser": "^4.4.3",
"@angular/platform-browser-dynamic": "^4.4.3",
"@angular/platform-server": "^4.4.3",
"@angular/router": "^4.4.3",
"@angular/upgrade": "^4.4.3",
"bcryptjs": "^2.4.3",
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"core-js": "^2.5.1",
"debug": "~2.6.3",
"express": "^4.15.5",
"hammerjs": "^2.0.8",
"hbs": "~4.0.1",
"jsonwebtoken": "^8.0.1",
"mongoose": "^4.11.12",
"mongoose-unique-validator": "^1.0.6",
"morgan": "~1.8.1",
"portfinder": "^1.0.13",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.4.3",
"serve-favicon": "~2.4.2",
"webpack": "^3.6.0",
"zone.js": "^0.8.17"
},
"devDependencies": {
"@types/core-js": "0.9.36",
"@types/node": "6.0.45",
"angular-router-loader": "^0.6.0",
"angular2-template-loader": "^0.6.2",
"awesome-typescript-loader": "^3.1.2",
"del-cli": "^0.2.0",
"file-loader": "^1.1.5",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.30.1",
"image-webpack-loader": "^3.4.2",
"raw-loader": "^0.5.1",
"style-loader": "^0.18.2",
"ts-loader": "^2.0.3",
"typescript": "^2.5.2",
"webpack": "^2.2.1",
"webpack-merge": "^4.1.0"
}
}
Specifically refering to this command:具体参考这个命令:
"build:prod": "del-cli public/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'public/js/app/**/*.js' 'public/js/app/**/*.js.map' '!public/js/app/bundle.js' '!public/js/app/*.chunk.js' 'assets/app/**/*.*.ngfactory.ts' 'assets/app/**/*.shim.ts' 'assets/app/**/*.ngsummary.json' 'assets/app/**/*.ngstyle.ts'"
When the build comes out successful, My project gets cluttered with .ngsummary.json & ngfactory.ts files, which should be deleted by the build:prod script.当构建成功时,我的项目会被 .ngsummary.json 和 ngfactory.ts 文件弄得乱七八糟,这些文件应该被 build:prod 脚本删除。 All the other file types gets deleted (they don't show up in my working directory, but only in the target directory).
所有其他文件类型都被删除(它们不会出现在我的工作目录中,而只出现在目标目录中)。
I guess i should include my webpack.config files - These are divided in 3:我想我应该包括我的 webpack.config 文件 - 它们分为 3 个:
webpack.config.common.js: webpack.config.common.js:
var webpack = require('webpack');
module.exports = {
entry: {
'app': './assets/app/main.ts'
},
resolve: {
extensions: ['.js', '.ts']
},
module: {
rules: [
{
test: /\.html$/,
use: [{ loader: 'html-loader' }]
},
{
test: /\.css$/,
use: [{ loader: 'raw-loader' }]
}
],
exprContextCritical: false
}
};
webpack.config.dev.js: webpack.config.dev.js:
var path = require('path');
var webpackMerge = require('webpack-merge');
var commonConfig = require('./webpack.config.common.js');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
path: path.resolve(__dirname + '/public/js/app'),
publicPath: "/js/app/",
filename: 'bundle.js',
chunkFilename: '[id].chunk.js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{loader: 'awesome-typescript-loader', options: {
transpileOnly: true
}},
{loader: 'angular2-template-loader'},
{loader: 'angular-router-loader'}
]
}
]
}
});
webpack.config.prod.js: webpack.config.prod.js:
var path = require('path');
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var commonConfig = require('./webpack.config.common.js');
module.exports = webpackMerge.smart(commonConfig, {
entry: {
'app': './assets/app/main.aot.ts'
},
output: {
path: path.resolve(__dirname + '/public/js/app'),
filename: 'bundle.js',
publicPath: '/js/app/',
chunkFilename: '[id].[hash].chunk.js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
'awesome-typescript-loader',
'angular2-template-loader',
'angular-router-loader?aot=true'
]
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
})
]
});
I am using windows 10 if it has anything to do with OS permissions - which i doubt, but you never know.如果它与操作系统权限有关,我正在使用 Windows 10 - 我怀疑,但你永远不知道。
EDIT: Think i should add tsconfig.json:编辑:认为我应该添加 tsconfig.json:
{
"compilerOptions": {
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es5",
"dom"
]
}
}
and tsconfig.aot.json:和 tsconfig.aot.json:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./public/js/app"
},
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es5",
"dom"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
}
}
I have a same problem, solution is tsconfig.aot.json我有同样的问题,解决方案是 tsconfig.aot.json
{
"compilerOptions": {
"target": "es6",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./public/js/app"
},
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es5",
"es6",
"es2015",
"es2017",
"dom",
"scripthost"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
}
}
tsconfig.json配置文件
{
"compilerOptions": {
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es5",
"es2015",
"es2017",
"dom",
"scripthost"
]
}
}
I had some similar issues getting my production build to cleanup after success.我有一些类似的问题,让我的生产构建在成功后清理。 My sample project is very similar to the OP.
我的示例项目与 OP 非常相似。 The big difference is that I am using the latest Angular version which is currently 7.2.9.
最大的不同是我使用的是最新的 Angular 版本,目前是 7.2.9。 I did not change the lib section as suggested.
我没有按照建议更改 lib 部分。 I removed the single quotes from each path description.
我从每个路径描述中删除了单引号。 So instead of this (from my package.json):
所以而不是这个(来自我的 package.json):
"build:prod": "del-cli dist && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail
&& del-cli 'src/**/*.js' 'src/app/**/*.ngfactory.ts' 'src/app/**/*.js.map'
I did this:我这样做了:
"build:prod": "del-cli dist && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail
&& del-cli src/**/*.js src/app/**/*.ngfactory.ts src/app/**/*.js.map
This did work for me.这对我有用。 I realize there is quite a gap between Angular 4 (OP's version) and Angular 7 (my version), however my issue seemed identical to the OP.
我意识到 Angular 4(OP 的版本)和 Angular 7(我的版本)之间存在很大差距,但是我的问题似乎与 OP 相同。 My guess is that del-cli lib has not changed significantly in a while.
我的猜测是 del-cli lib 有一段时间没有显着变化。
Added relevant package.json:添加了相关的 package.json:
"dependencies": {
"@angular/common": "^7.2.9",
"@angular/compiler": "^7.2.9",
"@angular/compiler-cli": "^7.2.9",
"@angular/core": "^7.2.9",
"@angular/forms": "^7.2.9",
"@angular/http": "^7.2.9",
"@angular/platform-browser": "^7.2.9",
"@angular/platform-browser-dynamic": "^7.2.9",
"@angular/platform-server": "^7.2.9",
"@angular/router": "^7.2.9",
"@angular/upgrade": "^7.2.9",
"core-js": "^2.6.5",
"rxjs": "^6.4.0",
"zone.js": "^0.8.29"
},
"devDependencies": {
"@ngtools/webpack": "^7.3.6",
"@types/core-js": "^2.5.0",
"@types/node": "^11.11.3",
"angular-router-loader": "^0.8.5",
"angular2-template-loader": "^0.6.2",
"awesome-typescript-loader": "^5.2.1",
"del-cli": "^1.1.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"raw-loader": "^1.0.0",
"typescript": "^3.2.4",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-merge": "^4.2.1"
}
Note: I am running on a windows 10 system.注意:我在 Windows 10 系统上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.