Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Output files to a different dir #32

Closed
guocheng opened this issue Jul 31, 2015 · 9 comments
Closed

Output files to a different dir #32

guocheng opened this issue Jul 31, 2015 · 9 comments

Comments

@guocheng
Copy link

Hello,

I am building an web app using bootstrap. I had this line to include the .css file

var Bootstrap  = require('../../node_modules/bootstrap/dist/css/bootstrap.min.css');

I would like to output the corresponding font files that bootstrap.min.css relies on to /dist/css/

Here is a simplified version of my webpack.config.js:

module.exports = {
    entry: {
        app: path.resolve(__dirname, 'app/src/index.js'),
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '../js/[name].js'
    },
    module: {
        loaders:[{
            test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: 'file-loader'
        }]

How can I config file-loader to output the font files to /dist/css instead of /dist/?

Thank you!

@hkongm
Copy link

hkongm commented Aug 19, 2015

same question.

@ghost
Copy link

ghost commented Aug 20, 2015

it is not a bug, you can add a query parameter name=xxx like this

    {
                test: /\.(png|jpg)$/,
                loader: 'url-loader?limit=100000&name=./imgs/[hash].[ext]'
    }

see loader-utils source code

@ghost
Copy link

ghost commented Sep 29, 2016

If you want for example emit your files at fonts/some-font.ttf
loader: "file?name=./fonts/[hash].[ext]"
But you are already extracting your css into css/styles.css
new ExtractTextPlugin('css/app.css', { allChunks: true })

Your css files will try load the fonts from css/fonts/...
Because they expect to be in the root of the public folder.

You can fix this by giving the publicPath query to the file-loader

loader: "file?publicPath=../&name=./fonts/[hash].[ext]"

This will emit the files in fonts/* and but the publicPath will be .././fonts/** in your css file..

Maybe it helps some one..

@lpil
Copy link

lpil commented Oct 3, 2016

Thanks for the tip! It would be great if this option was documented in the README.

@SpaceK33z
Copy link
Contributor

Closing since the question has been answered. Feel free to add this to the readme with a PR.

@davevans
Copy link

ps: the param to the file-loader is publicPath - beware cut and paste of pubicPath from above

@netojose
Copy link

@dropfen , publicPath QueryString, best tip ever. Thanks!

@tomwang1013
Copy link

we can also set the publicPath to an absolute path, so the assets can be accessed by all css

@jimmerioles
Copy link

jimmerioles commented Oct 20, 2017

that sneaky publicPath=../ 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants