赞助 webpack,同时从官方商店购买衣服 所有收益将转到我们的 open collective

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

$ npm install raw-loader --save-dev

在然后 webpack 配置中添加 loader:

file.js

import txt from './file.txt';

webpack.config.js

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.txt$/i,
        use: 'raw-loader',
      },
    ],
  },
};

或者,通过命令行使用:

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

然后,运行 webpack

示例

Inline

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

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

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