1

嘿伙计们(使用 webpack 2.1.0-beta.22),所以我的配置中有以下配置webpack.base.js

entry: {
    client: "./client/index.js"
},
output: {
    path: _.outputPath,
    filename: '[name].js',
    publicPath: '/themes/default/dist/'
},
module: {
    loaders: [
        {
            test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
            loader: 'file',
            query: {
                name: 'media/[name].[hash:8].[ext]'
            }
        }
    ]
}

这在我的webpack.dev.js

const cssImagePath = path.resolve('../..');`

base.module.loaders.push(
    {
        test: /\.(s?)css$/,
        loaders: [
            'style-loader',
            `css-loader?sourceMap&root=${cssImagePath}`,
            'sass-loader?outputStyle=expanded&sourceMap&sourceMapContents'
        ]
    }
)

现在我的scss文件中有这一行:background-image: url('/themes/default/client/images/snow-flake.png');

如果我运行 webpack 并使用检查器,则路径将被替换为:url(/themes/default/dist/media/snow-flake.0af467e3.png)

哪个看起来完美的问题是file-loader没有创建/复制到该目录所以themes/default/dist/media不存在?

有人遇到过这个吗?

4

0 回答 0