Tag: raw loader

如何使用Webpack 2 Raw-Loader来读取文件

我目前被困在一个地方,我需要以HTTPS模式启动NodeJS服务器,并且需要读取cert文件,以便在https.createServer(options, app).listen(8443)命令中给出这些选项。 我很难理解如何将文件读入使用Webpack 2捆绑的TypeScript文件中。例如, 我有2个文件file.crt和file.key。 我想在创buildhttps服务器时开始读取这些文件,并开始监听给定的端口。 在常规TS / JS土地上我可以这样做: “` import Config from '../env/config'; import Express from '../lib/express'; import * as https from 'https'; import * as fs from 'fs'; let config = new Config(); let app = Express.bootstrap().app; export default class AppService{ constructor(){ // console.log('blah:', fs.readFileSync('./file.txt')); } start(){ let options = { key: fs.readFileSync('file.key'), […]

在webpack上,我应该怎么做“module.exports ='html_template_content'”

所以我想用webpack做一个非常简单的任务。 我有几个像例如静态的HTML模板 的test.html <div><span>template content</span></div> 我想要做的就是返回模板内的string,例如 require("raw!./test.html") 与应该返回一个string,如: "<div><span>template content</span></div>" 但相反,它返回以下string "modules.exports = <div><span>template content</span></div>" 我已经尝试了几个模块,比如raw-loader和html-loader。 而且它们的行为方式都是一样的。所以我查看了源代码,只是为了发现它的SUPPOSED行为是这样的。 那么,如果我只是想要原始的HTML,我到底想要做什么呢? 删除前面的“module.exports =”string是不是一个坏习惯? 从捆绑编辑:删除'modules.export ='部分结果束没有返回:/ 我的configuration module.exports = { module: { loaders: [ { test: /\.html$/, loader: "raw-loader" } ] } };