0.0.4 • Published 6 years ago

contents-file-loader v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

A very simple file loader module for webpack, that returns file contents

At this moment, loader supports only files with json content, for example:

{
  "hello": "Hello world!"
}

Requirements

This module was tested with webpack 4.2.0 and higher

Getting Started

To begin, you'll need to install contents-file-loader:

$ npm install contents-file-loader --save-dev

Import (or require) the target file(s) in one of the bundle's files:

// bundle file
import config from './file.json'

Then add the loader to your webpack config. For example:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.json$/, 
        type: 'javascript/auto',               
          use: [
           {         
            loader: "contents-file-loader",                        
           }                   
        ]
      }
    ]
  }
}

You could also specify the name of emitted file:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.json$/, 
        type: 'javascript/auto',               
          use: [
           {         
            loader: "contents-file-loader",
            options: {
               name: "[hash].[ext]"
             }                        
           }                   
        ]
      }
    ]
  }
}

And run webpack via your preferred method. This will emit file.json as a file in the output directory and returns contents of the file.

License

MIT

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago