如何设置Webpack用于Express.js应用程序,而不是React应用程序?

5

我需要使用Express.js,jade和less创建应用程序,并希望使用webpack将应用程序组合成包。

整个互联网上都充满了有关为react设置webpack的文章,但没有一篇是关于为普通的Express应用程序配置webpack以及如何从.less文件制作common.css的文章。

请帮助我!


出于好奇,你希望从Webpack中获得哪些好处,这些好处在Express本身中缺少? - James LeClair
1个回答

1
  • https://github.com/webpack/less-loader
  • https://github.com/webpack/jade-loader

    require("jade!./template.jade");  
    // => uses the "jade-loader" (that is installed from npm to "node_modules")  
    //    to transform the file "template.jade"  
    
    require("!style!css!less!bootstrap/less/bootstrap.less");  
    // => the file "bootstrap.less" in the folder "less" in the "bootstrap"  
    //    module (that is installed from github to "node_modules") is  
    //    transformed by the "less-loader". The result is transformed by the  
    //    "css-loader" and then by the "style-loader".  
    
使用 ! 分隔加载器。
查看 webpack 文档中的配置 API,了解如何设置捆绑过程的示例。只需要定义您的入口点和目的地。
如果您正在寻找自动刷新,请查看 webpack dev server API。

我已经了解了关于“loaders”的知识——它们没有问题。问题在于如何从“.less”文件中获取“common.css”和其他分块的CSS。 - Vadim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接