如何在Aurelia / Webpack骨架中覆盖插件的主要属性?

时间:2016-08-26 07:47:31

标签: webpack aurelia

我在基于webpack骨架的aurelia-gravatar应用程序中使用demo Aurelia/enhance插件。

要使其有效,我必须手动将"main": "dist/commonjs/index.js",添加到node_modules/aurelia-gravatar-component/package.json

有没有办法如何从应用package.json覆盖?这对我不起作用:

  "aurelia": {
    "build": {
      "resources": [
        "aurelia-gravatar-component/gravatar"
      ]
    },
    "moduleRootOverride": {
      "aurelia-gravatar-component": "dist/commonjs"
    }
  },

浏览器中的错误为Error: Cannot find module './aurelia-gravatar-component'.

如何快速测试演示应用程序:

# get the demo app
git clone https://github.com/k2s/aurelia-skeleton-esnext-webpack-enhance.git
cd aurelia-skeleton-esnext-webpack-enhance
npm install

# manually add '"main": "dist/commonjs/index.js",' to 'node_modules/aurelia-gravatar-component/package.json'

# start serving the application
npm start
# open the application in browser
xdg-open http://localhost:9000

1 个答案:

答案 0 :(得分:1)

动态导入插件时,您可以直接引用主文件。在src/main.js文件中,只需按以下方式配置插件,直到项目修复其package.json

aurelia.use
  .standardConfiguration()
  .developmentLogging()
  .plugin('aurelia-gravatar-component/dist/commonjs/index')
  .globalResources('hello')

您还需要将该文件添加到package.json的构建资源中:

"aurelia": {
  "build": {
    "resources": [
      "aurelia-gravatar-component/dist/commonjs/index",
      "aurelia-gravatar-component/dist/commonjs/gravatar"
    ]
  },
},

但最终aurelia-gravatar应定义main - 随时向该项目提交错误报告。

希望有所帮助。