webpackloaderonnx

WebPack Loader for ONNX models


I have multiple onnx models, and I want to load them dynamically using webpack file-loader plugin.

webpack.config.js

module: {
    rules: [
    /* File Loader*/
    {
        test: /\.(glb|onnx)$/i,
        use:
        [
            {
                loader: 'file-loader',
                options:
                {outputPath: 'assets/resource/'}
             }
        ]
    }]
}

But My .onnx files (located in the src/assets/models/*.onnx) are not copied dynamically to the dest folder,

can you please tell me how can I load the onnx models using the file-loader correctly? thanks in advance.


Solution

  • I solved it by copying the whole directory using the copy-webpack-plugin:

    const path = require('path');
    const CopyPlugin = require("copy-webpack-plugin");
    
        plugins: [
            /* Copy Plugin */
            new CopyPlugin({
                patterns: [
                    { 
                        from: path.resolve(__dirname, 'src/assets/models'), 
                        to: path.resolve(__dirname, 'dist/models/') 
                    },
                ]
            }),
        ]