0

Let's say I have a simple loader, that's supposed to just move a file from source to deploy, i've just copied the rule alone for simplistic state.

{
    test: /\.cshtml$/,
    use : [{
        loader : 'file-loader',
        options :  {
            name : '[path][name].[ext]',  
            // context :'',
            // outputPath : ''  
        }
    }]
}

I've tried a million different combinations with this one, basically once the file-loader processes it, it copies it to the output.path in webpack config, the path is something like this:

/outputpath/thenfilefromloader/to/folder/goes/here/nameoffile.cshtml

What' I'm trying to do, is more or less, split the string after goes and concat with output path:

/outputpath/goes/here/nameoffile.cshtml

Is this even achievable? Basically I'm trying to get rid of gulp, these files were just copied with gulp and that's it, but the path was manipulated before it was copied.

Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95

1 Answers1

0

If I get what you are trying to do, replacing [path] placeholder with a defined path should do the work:

{
    test: /\.cshtml$/,
    use : [{
        loader : 'file-loader',
        options :  {
            name : 'goes/here/[name].[ext]',  
        }
    }]
}

You also might add a hash placeholder to avoid filename collisions:

name : 'goes/here/[name].[hash].[ext]',
Andrea Carraro
  • 9,731
  • 5
  • 33
  • 57
  • Yes, but it would need to be dynamic for every file, there's a few rules based on their directory – Shannon Hochkins May 14 '17 at 22:02
  • The file-loader gives you quite a lot flexibility [filename templates](https://github.com/webpack-contrib/file-loader#filename-templates). I've never tryed myself, but it should also accept a function since it uses [webpack's interpolateName loader-utils](https://github.com/webpack/loader-utils/blob/master/lib/interpolateName.js) under the hoods. – Andrea Carraro May 15 '17 at 16:37