Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: quickstart doc for nunjucks config #732

Closed
wants to merge 1 commit into from
Closed

fix: quickstart doc for nunjucks config #732

wants to merge 1 commit into from

Conversation

hbrls
Copy link
Contributor

@hbrls hbrls commented Apr 9, 2017

fix issue #525

@mention-bot
Copy link

@hbrls, thanks for your PR! By analyzing the history of the files in this pull request, we identified @atian25, @huacnlee and @pmq20 to be potential reviewers.

@popomore
Copy link
Member

popomore commented Apr 9, 2017

这个原来并没有问题

@popomore popomore closed this Apr 9, 2017
@hbrls
Copy link
Contributor Author

hbrls commented Apr 9, 2017

https://github.com/hbrls/egg-nunjucks 这个例子跑不起来,run/config 看到是这样的

    "view": {
      "root": [
        "/Users/hbrls/github/egg-nunjucks/app/view"
      ],
      "cache": false,
      "defaultExtension": ".html",
      "defaultViewEngine": "",
      "mapping": {}
    },
    "nunjucks": {
      "autoescape": true,
      "throwOnUndefined": false,
      "trimBlocks": false,
      "lstripBlocks": false,
      "cache": false
    },
    ...
    "view": {
      "enable": true,
      "package": "egg-view",
      "name": "view",
      "dependencies": [],
      "optionalDependencies": [],
      "env": [],
      "from": "/Users/hbrls/github/egg-nunjucks/node_modules/egg/config/plugin.js",
      "path": "/Users/hbrls/github/egg-nunjucks/node_modules/egg-view",
      "version": "1.1.0"
    },
    "nunjucks": {
      "enable": true,
      "package": "egg-view-nunjucks",
      "name": "nunjucks",
      "dependencies": [
        "security",
        "view"
      ],
      "optionalDependencies": [],
      "env": [],
      "from": "/Users/hbrls/github/egg-nunjucks/config/plugin.js",
      "path": "/Users/hbrls/github/egg-nunjucks/node_modules/egg-view-nunjucks",
      "version": "2.0.0"
    }

@popomore
Copy link
Member

popomore commented Apr 9, 2017

学习一下 node 基础吧

@hbrls
Copy link
Contributor Author

hbrls commented Apr 9, 2017

我觉得我改的和这个解释没什么不同啊,还望明示,还是说熟悉node的开发者看到上面的写法应该能意识到需要改成下面的写法

@popomore
Copy link
Member

popomore commented Apr 9, 2017

应该说两种都可以,但不能同时写 exports 和 module.exports,可以上网查一下

@hbrls
Copy link
Contributor Author

hbrls commented Apr 9, 2017

那个issue中给了链接,我看过了,我的意思是 egg-init 出来的写法是 module.exports,而且考虑到返回函数的灵活性更好,我猜这也是推荐的方式

所以我的问题应该是去看 egg-init 及其 template 吗,我希望的效果是上手能用,只推荐一种基于经验的最佳实践

@popomore
Copy link
Member

popomore commented Apr 9, 2017

没有啊,这个 node 的特性,没有最佳写法,如果不用参数何必这样写呢。

@hbrls
Copy link
Contributor Author

hbrls commented Apr 9, 2017

好的,刚刚去翻了下egg/examples/view-nunjucks/config,懂了,抱歉麻烦你这么晚

@rorivers
Copy link

我也遇到了这个坑。
准备模仿egg-view-ejs,写一个view插件。
代码基本照抄egg-view-ejs的,命名成egg-view-vhtml。
我在config/plugin.js里加了如下配置:

const path = require('path');

module.exports = () => {
    const exports = {};

    //...

    exports.vhtml = {
      enable: true,
      path: path.join(__dirname, '../lib/plugin/egg-view-vhtml'),
    };

    return exports;
}

然后,就报错了,Cann't find ViewEngine "vhtml"。

看到Egg.js的启动log里,有内置的egg-view,egg-session等插件。
我就想,难道是我vhtml插件里代码有问题。那我直接用egg-view-ejs。

const path = require('path');

module.exports = () => {
    const exports = {};

    //...

    exports.ejs = {
      enable: true,
      package: 'egg-view-ejs',
    };

    return exports;
}

现在报Cann't find ViewEngine 'ejs'。

直到我看到这个issuse。才发现Egg.js的插件配置
config/plugin.js大都这样写:

exports.static = true;

exports.reactssr = {
  enable: true,
  package: 'egg-view-react-ssr',
};

exports.ejs = {
  enable: true,
  package: 'egg-view-ejs',
};

我改,还不行吗?
然后就世界和平了。

@zhoudad
Copy link

zhoudad commented Nov 26, 2020

module.exports = {
 // had enabled by egg
 // static: {
 //   enable: true,
 // }
 nunjucks: {
   enable: true,
   package: 'egg-view-nunjucks',
 }
};

这样子可以。。文档误人啊

@atian25
Copy link
Member

atian25 commented Nov 26, 2020

这不是 Node 基础常识么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants