How to extract multiple theme stylesheets with webpack?

后端 未结 2 1663
北恋
北恋 2021-02-02 00:51

I am trying to make a React app themeable. For now themes only consist of different sets of Sass variables which define different header colors, etc.

From my current und

2条回答
  •  遇见更好的自我
    2021-02-02 00:54

    Here's your solution:

    npm i --save-dev file-loader
    

    In the loaders section, add this:

    {
        test: /themes\/.+\.scss$/,
        loader: "file-loader?name=./compiled-themes/css/[name].css!css!sass"
    },
    

    There may be more scss files, if so there must be another section which bundles them as usual, but skips the themes:

    {
        test: /\.scss$/,
        exclude: /themes\/.+\.scss$/,
        loader: "css!sass"
    },
    

    The file loader writes files by filename, hash and extension so you are able to preserve the name.

    Note the name=./compiled-themes/css/[name].css part, where [] vars are substituted.

    https://github.com/webpack/file-loader

提交回复
热议问题