有人可以向我解释一下,这个构建时 require
是如何工作的吗?
https://github.com/kriasoft/react-starter-kit/blob/feature/redux/src/server.js#L89
他们需要一个jade
模板,哪个包或配置允许这个,我自己好像找不到。
const template = require('./views/index.jade')
我觉得这样更优雅:
import jade from 'jade'
const template = jade.compile('./views/index.jade')
最佳答案
作为RGraham mentioned in his comment ,require
调用在 webpack 编译应用程序包期间被“拦截”。这是使用 "loaders" 完成的为特定类型的导入定义特定行为:
Loaders allow you to preprocess files as you require() or “load” them.
在这种特殊情况下,执行此修改的加载器可能是其中之一(或者我在搜索中没有找到的另一个):
编辑:查看 project's own webpack configuration我们可以看到它是上面的第二个链接:
{
test: /\.jade$/,
loader: 'jade-loader',
}
关于javascript - 在 react-starter-kit 中需要 ('template.jade' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387568/