Express Generator Without Jade

后端 未结 6 1212
南方客
南方客 2021-02-07 03:46

I am trying to generate an express skeleton, using the express generator. So it would be this:

$ npm install express-generator -g

However, it

相关标签:
6条回答
  • 2021-02-07 04:01

    Try running this command in command prompt:

    express --help
    

    It will give you the express generator help:

      Usage: express [options] [dir]
    
      Options:
    
        -h, --help          output usage information
            --version       output the version number
        -e, --ejs           add ejs engine support
            --hbs           add handlebars engine support
            --pug           add pug engine support
        -H, --hogan         add hogan.js engine support
            --no-view       generate without view engine
        -v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
        -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
            --git           add .gitignore
        -f, --force         force on non-empty directory
    

    Source: https://expressjs.com/en/starter/generator.html

    The above options give you the list of "view engines".

    Now, simply type:

    express -{your choice view engine}


    For example using express -e:

    This sets the EJS engine as your view handler and removes jade. EJS has the look and feel of HTML with the added ability to inject values via their template system.

    0 讨论(0)
  • 2021-02-07 04:04

    This generator seems to handle EJS templates. EJS is just HTML with the ability to insert variables. Well... Like a templating engine. But EJS is also the rendering engine for HTML.

    In the app.js of the generator you can see this line (15):

    app.set('view engine', '{views}');
    

    So my guess is that if you select the EJS engine when installing, it will be good. As long as you put your html files in the specified folder (line 14, app.js):

    app.set('views', path.join(__dirname, 'views'));
    
    0 讨论(0)
  • 2021-02-07 04:10

    If you won't a view engine just type:

    express --no-view
    

    You can add an engine after or not working with server rendering.

    0 讨论(0)
  • 2021-02-07 04:13

    You can also directly include your html file into your jade file

    include ../../public/index.html
    
    0 讨论(0)
  • 2021-02-07 04:14

    You can just delete the jade files and hook up your own template engine.

    For example, I like using Handlebars.js. So in order to use that, in app.js or server.js or whatever the generator names the main file, you'd substitute the line:

    app.set('view engine', 'jade');
    

    with something along the lines of this (after installing and requiring handlebars, at least):

    app.engine('handlebars', exphbs({defaultLayout: 'main'}));
    app.set('view engine', 'handlebars');
    

    And every engine is as configurable as you want it o be.

    0 讨论(0)
  • 2021-02-07 04:17

    You can check the documentation Express-Generator.

    As you can see with express -h the view engine suported by express generator are (ejs|hbs|hjs|jade|pug|twig|vash), but by deafult jade is suported.

    $ express -h

    Usage: express [options][dir]

    Options:

    -h, --help          output usage information
        --version       output the version number
    -e, --ejs           add ejs engine support
        --hbs           add handlebars engine support
        --pug           add pug engine support
    -H, --hogan         add hogan.js engine support
    -v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
    -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory
    
    0 讨论(0)
提交回复
热议问题