如何使用webpack bundler在aurelia.json文件app中配置第三方库

时间:2018-05-05 07:57:33

标签: webpack aurelia aurelia-cli aurelia-framework

我刚刚使用以下项目配置创建了Aurelia-CLI(v0.33.1)应用程序:

(y)

我很难在这个项目中尝试配置第三方插件,因为每个其他插件都希望我对aurelia.json文件中的Name: Sample Platform: Web Bundler: Webpack Loader: None Transpiler: TypeScript Markup Processor: Minimal Minification CSS Processor: Sass Unit Test Runner: Karma Integration Test Runner: Protractor Editor: Visual Studio Code 部分或webpack.config中的build.bundles.dependencies部分进行更改。 js文件,而这些部分完全没有从各自的文件中删除。

为了增加痛苦,coreBundles.aurelia命令失败并显示消息"错误:此命令仅适用于Aurelia CLI Bundler"

例如 aurelia-charts

https://github.com/SpoonX/aurelia-charts/blob/master/README.md#aureli-cli 它说:

  

Aurelia-view-manager使用extend,array-equal和typer,所以添加   以下是build.bundles.dependencies部分   奥里利亚项目/ aurelia.json

https://github.com/SpoonX/aurelia-charts/blob/master/README.md#webpack

它说:

  

在你的coreBundles.aurelia部分添加aurelia-charts   webpack.config.js

看看au install <package_name>看起来如何:

aurelia.json

这是我的{ "name": "sample", "type": "project:application", "bundler": { "id": "webpack", "displayName": "Webpack" }, "build": { "options": { "server": "dev", "extractCss": "prod", "coverage": false } }, "platform": { "id": "web", "displayName": "Web", "port": 8080, "hmr": false, "open": false, "output": "dist" }, "loader": { "id": "none", "displayName": "None" }, "transpiler": { "id": "typescript", "displayName": "TypeScript", "fileExtension": ".ts" }, "markupProcessor": { "id": "minimum", "displayName": "Minimal Minification", "fileExtension": ".html" }, "cssProcessor": { "id": "sass", "displayName": "Sass", "fileExtension": ".scss" }, "editor": { "id": "vscode", "displayName": "Visual Studio Code" }, "unitTestRunner": [ { "id": "karma", "displayName": "Karma" } ], "integrationTestRunner": { "id": "protractor", "displayName": "Protractor" }, "paths": { "root": "src", "resources": "resources", "elements": "resources/elements", "attributes": "resources/attributes", "valueConverters": "resources/value-converters", "bindingBehaviors": "resources/binding-behaviors" }, "testFramework": { "id": "jasmine", "displayName": "Jasmine" } } 文件:

webpack.config.js

1 个答案:

答案 0 :(得分:0)

当你选择webpack时,aurelia-cli唯一能做的就是“包装”各种调用,并为参数和构建任务提供一些语法糖。因此,您可以完全停止查看// check if directory exists // then make medicine directory char *temp1 = "C:\\pharmaCMS\\db\\medicine\\"; char *result = malloc(sizeof(strlen(temp1) + strlen(medicine.name))); strcpy(result, temp1); strcat(result, medicine.name); struct stat sb; if (stat(result, &sb) == 0 && S_ISDIR(sb.st_mode)) { printf("YES\n"); } else { printf("NO\n"); CreateDirectory("C:\\pharmaCMS", NULL); CreateDirectory("C:\\pharmaCMS\\db", NULL); CreateDirectory("C:\\pharmaCMS\\db\\medicine", NULL); CreateDirectory(result, NULL); } ,并将注意力集中在aurelia.json

使用webpack,您无需显式配置依赖项 - 您配置的唯一内容是用于处理各种文件类型的加载程序和插件。您需要做的就是在应用程序的某处导入依赖项,webpack将在构建期间找到它并包含它。

在这方面,您在指南或博客中看到的与webpack.config有关的任何说明 - 只是忽略它们,并首先尝试“天真地”只是在某处导入依赖项。在大多数情况下,它确实会起作用。