0.0.4 • Published 7 years ago
contents-file-loader v0.0.4
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-devImport (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.