【发布时间】:2016-10-05 12:09:19
【问题描述】:
我正在尝试将我的一个自定义元素移动到一个插件中,以便我可以跨项目重复使用它。
我查看了skeleton plugin 并注意到它有一个src/index.js,它返回一个配置,其中所有自定义元素都定义为globalResources。
所以我尝试了同样的事情,我基本上有:
src/index.js
export function configure (config) {
config.globalResources([
'./google-map',
'./google-map-location-picker',
'./google-map-autocomplete'
]);
}
然后我将每个自定义元素放在index.js 旁边,例如:
google-map.js
import {inject, bindable, bindingMode, inlineView} from 'aurelia-framework';
@inlineView(`
<template>
<div class="google-map"></div>
</template>
`)
@inject(Element)
export class GoogleMapCustomElement {
// All the Custom Element code here
}
我还设置了一个基本的 npm 脚本,它在代码上运行 babel 并将其粘贴在 dist/ 中:
"main": "dist/index.js",
"babel": {
"sourceMap": true,
"moduleIds": false,
"comments": false,
"compact": false,
"code": true,
"presets": [ "es2015-loose", "stage-1"],
"plugins": [
"syntax-flow",
"transform-decorators-legacy",
"transform-flow-strip-types"
]
},
"scripts": {
"build": "babel src -d dist"
},
Tbh 我不完全确定这一切是否正确,但我从骨架插件中获取了一些,它似乎运行良好。
无论如何,我遇到的问题是,在我安装插件 (npm install --save-dev powerbuoy/AureliaGoogleMaps) 后,将其添加到我的 aurelia.json build.bundles[vendor-bundle.js].dependencies 并告诉 aurelia 在 main.js (.use.plugin('aurelia-google-maps')) 中使用它我明白了:
GET http://localhost:9000/node_modules/aurelia-google-maps/dist/index/google-map.js (404)
所以我的问题是,它从哪里得到dist/index/ 部分?我在index.js 中配置了我的globalResources,但它没有说我有一个index 文件夹。
我做错了什么?
额外问题:转换我的 ES6 插件代码以便其他人可以使用它的最低要求是多少?我的 babel 配置看起来正确吗?
【问题讨论】:
-
你是如何将它添加到 aurelia.json 文件中的?就像“google-map”一样,还是您指定了自定义配置? “谷歌地图”:{....}?
-
我刚刚添加了“aurelia-google-maps”,但我也尝试过
{"name": "aurelia-google-maps", "path": "../node_modules/aurelia-google-maps/dist/index"}。两者都产生相同的结果。我确实相信“aurelia-google-maps”可以正常工作(因为我的主要属性指向 index.js) -
我不确定 为什么 它会失败,但问题可能与 Aurelia 如何将您路由到可能由名为 @ 的文件定义的页面有关987654340@,但 URL 显示
localhost:9000/about。在这种情况下,如果从index.js发出GET请求的算法询问服务器,“我现在在哪里?”服务器给它dist/index,然后./google-map当然指向dist/index/google-map。所以问题是为什么该算法被输入dist/index而不是dist/index.js。这是唯一对我有意义的方式。
标签: aurelia