我正在尝试将资源加载到我的css中,在某些情况下(较大的文件),请复制到特定目录。当使用url加载器,并为名称模板定义查询参数时,我收到错误:
错误:路径变量[name]未在此上下文中实现: [路径] [名称]。[EXT]?7770f0c15c5bc5d8291a
我正在使用具有已定义输出的多个入口点,我不确定这是否是问题。有没有办法强制上下文? Webpack配置如下。
module.exports = [{
debug: !isProduction,
devtool: isProduction ? false : 'source-map',
entry: {
// Globals:
'./public/dist/css/base' : './src/scss/base',
'./public/dist/css/module' : './src/scss/module',
},
output: {
path: __dirname,
filename: '[name].css',
},
module: {
loaders: [
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', ['css?sourceMap', 'postcss', 'sass?sourceMap'])
}, {
test: /.*\.(gif|png|jpe?g|svg)$/i,
loaders: [
'url?{limit: 2048, name: "[path][name].[ext]?[hash]"}'
],
include: path.join(__dirname, 'src/images')
}
]
},
resolve: {
extensions: ['', '.css', '.scss'],
root: [path.join(__dirname, './src')]
},
plugins: plugins,
resolveUrlLoader: {
root: './public/dist/images'
},
postcss: [
autoprefixer({
browsers: ['last 2 versions']
})
],
sassLoader: {
includePaths: [path.resolve(__dirname, './src/scss')],
outputStyle: isProduction ? 'compressed' : 'expanded'
},
}]
这是我的文件结构:
- src
|- sass
|- js
|- images
- public
|- css
|- js
|- images