【发布时间】:2021-09-21 11:41:24
【问题描述】:
我在我的项目中添加了 angular-datatables 并自定义了我的表格。它可以在本地完美运行,但是当我将它放在生产服务器上时,所有自定义项都消失了 - 没有滚动条、没有排序选项、没有分页等。在我看来,该库在生产中丢失了。但它在我的 angular.json 中。我运行了构建。可能是什么问题?
这是我的 angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"pd-free-angularcli": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"allowedCommonJsDependencies": [
"chart.js"
],
"assets": [
"src/assets",
"src/assets/img/cloadlogo.png",
{
"input": "./node_modules/@google/markerclustererplus/images",
"glob": "*",
"output": "/images"
}
],
"styles": [
"src/styles.scss",
"src/assets/scss/cload-theme.scss",
"./node_modules/ngx-toastr/toastr.css",
"./node_modules/datatables.net-bs4/css/dataTables.bootstrap4.min.css",
"node_modules/datatables.net-dt/css/jquery.dataTables.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"./node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js",
"node_modules/jquery/dist/jquery.js"
],
"aot": false,
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "pd-free-angularcli:build"
},
"configurations": {
"production": {
"browserTarget": "pd-free-angularcli:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "pd-free-angularcli:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/arrive/src/arrive.js",
"./node_modules/moment/moment.js",
"./node_modules/bootstrap-notify/bootstrap-notify.js",
"https://code.jquery.com/jquery-3.4.1.min.js",
"https://unpkg.com/bootstrap-show-password@1.2.1/dist/bootstrap-show-password.min.js"
],
"styles": [
"src/styles.scss",
"src/assets/sass/cload-theme.scss"
],
"assets": [
"src/assets",
"src/assets/img/favicon.png",
"src/favicon.png"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json"
],
"exclude": []
}
}
}
},
"pd-free-angularcli-e2e": {
"root": "e2e",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "pd-free-angularcli:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": []
}
}
}
}
},
"defaultProject": "pd-free-angularcli",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss"
},
"@schematics/angular:directive": {
"prefix": "app"
}
},
"cli": {
"analytics": false
}
}
【问题讨论】:
-
显示什么样的错误?请删除一次 rm -rf 节点/模块并重新安装 npm 包 sudo npm i
-
ERROR TypeError: $(...).DataTable is not a function Angular 9 core.js:6456
-
这真的很有趣,因为我没有使用 Angular 9。我使用的是 Angular 12。
-
我也设法在本地重现了这个错误,现在不能再在本地旋转它了。我通过更改脚本和样式中的路径(添加或删除“./”)来复制它。不确定到底是哪一个使它起作用。哦,亲爱的。
标签: angular production angular-datatables angular12