You can also use the css-loader results directly as a string, such as in Angular's component style. Pay close attention to this next step as we'll be using the Node.js API and memfs to execute webpack. GitHub Gist: instantly share code, notes, and snippets. For example: toString. [ext] . npm install--save-dev file-loader Usage By default the filename of the resulting file is the MD5 hash of the file's contents with the original extension of the required resource. webpack.config.js Getting Started. Example Webpack Config File. To support files we run npm install --save-dev file-loader and npm install --save-dev url-loader. A loader for webpack that allows importing files as a String. Most likely you should use CopyWebpackPlugin which was mentioned in kevlened answer. import txt from './file.txt'; webpack.config.js We use ts-loader in this guide as it makes enabling additional webpack features, such as importing other web assets, a bit easier. Awesome Open Source is not affiliated with the legal entity who owns the " Webpack Contrib " organization. To begin, you'll need to install file-loader: $ npm install file-loader --save-dev Import (or require) the target file(s) in one of the bundle's files: // bundle file import img from './file.png' Then add the loader to your webpack config. test/example.txt. This lets us avoid emitting output to disk and will give us access to the stats data which we can use to grab our transformed module: npm install--save-dev webpack … For example: file.js. And run webpack via your preferred method. npm install file-loader --save-dev Add the loader to the Webpack configuration: For the example let’s try to move images from their directory to a brand new image folder with a naming convention of img-[hash]. Hey [name]! Alternativly for some kind of files like .html or .json you can also use raw-loader or json-loader. Only for webpack v4: Good loaders for requiring your assets are the file-loader and the url-loader which you should specify in your config (see below). ts-loader uses tsc, the TypeScript compiler, and relies on your tsconfig.json configuration. warning. Get code examples like "webpack file loader images in html webpack" instantly right from your google search results with the Grepper Chrome Extension. To begin, you'll need to install raw-loader: $ npm install raw-loader --save-dev Then add the loader to your webpack config. "File Loader" and other potentially trademarked words, copyrighted images and copyrighted readme contents likely belong to the legal entity who owns the "Webpack Contrib" organization. Install it via npm install -D raw-loader and then what you only need to do is to add another loader to our webpack… This will emit file.png as a file in the output directory (with the specified naming convention, if options are specified to do so) and returns the public URI of the file.. ℹ️ By default the filename of the resulting file is the hash of the file's contents with the original extension of the required resource. Make sure to avoid setting module to "CommonJS", or webpack won't be able to tree-shake your code. And run webpack via your preferred method.