raw-loader

[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![tests][tests]][tests-url] [![coverage][cover]][cover-url] [![chat][chat]][chat-url] [![size][size]][size-url]

可以将文件作为字符串导入的 webpack loader。

起步

你需要预先安装 raw-loader

  1. $ npm install raw-loader --save-dev

在然后 webpack 配置中添加 loader:

file.js

  1. import txt from './file.txt';

webpack.config.js

  1. // webpack.config.js
  2. module.exports = {
  3. module: {
  4. rules: [
  5. {
  6. test: /\.txt$/i,
  7. use: 'raw-loader',
  8. },
  9. ],
  10. },
  11. };

或者,通过命令行使用:

  1. $ webpack --module-bind 'txt=raw-loader'

然后,运行 webpack

示例

Inline

  1. import txt from 'raw-loader!./file.txt';

Beware, if you already define loader(s) for extension(s) in webpack.config.js you should use:

  1. import css from '!!raw-loader!./file.css'; // Adding `!!` to a request will disable all loaders specified in the configuration

Contributing

Please take a moment to read our contributing guidelines if you haven’t yet done so.

CONTRIBUTING

License

MIT