带有多个入口点的Webpack url loader上下文错误

时间:2016-04-26 23:52:49

标签: webpack bundling-and-minification webpack-style-loader

我正在尝试将资源加载到我的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

0 个答案:

没有答案