05/21/2017 Engineering Cody Reichert

A Webpack loader to move files from one location to another. Check out the repo.

We're excited to release a new NPM package called move-file-loader. move-file-loader is a Webpack loader for moving files from one location to another during compile time. At Assertible, we use this loader in our builds to share files between the frontend client and the backend server.

Webpack logo

move-file-loader usage

To use the move-file-loader, you just need to add a rule to your Webpack loaders configuration and add arguments that define when and how to move the file. Basic usage looks like this:

module.exports = {
    // ...your webpack config,
    module: {
        loaders: [{
            /**
             * This will move .json files to the [path]/[name].json
             * location after being processed by json-loader
             */
            test: /.json/,
            loader: "move-file-loader?name=[path][name].json"
        }]
    }
}

The loader definition above works on any .json filed required in your code. When a .json file is imported, move-file-loader will move the file to [path][name].json, where [path] is the output directory defined in your webpack config, and [name] is the name of the actual JSON file. And that's it!

Note that if you are using Webpack 2, the loaders array should be named rules.

Further development and contributing

If you have any feedback or ideas, feel free to open an issue on GitHub or send us a message on Twitter. Contributions are always appreciated, you can open a pull request any time.

:: Cody Reichert

Categories

The easiest way to test and
monitor your web services

Define and test your web service with Assertible Track and test API deployments across environments Schedule API monitoring and failure alerts

Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.

Sign up for free