Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何使用webpack从MDL获取svg_Css_Svg_Npm_Sass_Webpack - Fatal编程技术网

Css 如何使用webpack从MDL获取svg

Css 如何使用webpack从MDL获取svg,css,svg,npm,sass,webpack,Css,Svg,Npm,Sass,Webpack,使用复选框组件表单Material Design Lite,即。 使用时,tickmark.svg未正确显示 import '../../node_modules/material-design-lite/src/material-design-lite.scss'; 用于与npm和webpack捆绑。而不是: 我得到: 在浏览器中,我找到了tickmark.svg的以下路径,即“缺失”的svg: 当使用这两个备选方案中的任何一个时,其工作原理如下: 1) import'../../n

使用复选框组件表单Material Design Lite,即。

使用时,tickmark.svg未正确显示

import '../../node_modules/material-design-lite/src/material-design-lite.scss';
用于与npm和webpack捆绑。而不是:

我得到:

在浏览器中,我找到了tickmark.svg的以下路径,即“缺失”的svg:

当使用这两个备选方案中的任何一个时,其工作原理如下: 1)
import'../../node_modules/material design lite/.tmp/material design lite.css'
2) 
import'../../node_模块/material design lite/material.min.css'

要进行比较,使用2时,我会在浏览器中看到以下内容:

My webpack.config.js:

var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Clean = require('clean-webpack-plugin');
var bootstrapPath = path.join(__dirname, 'node_modules/bootstrap/dist/css');
var sourcePath = path.join(__dirname, 'assets');

module.exports = {
    devtool: 'eval-source-map',
    context: __dirname,
    entry: [
        './assets/js/index' // entry point of our app. .assets/js/index.js should require other js modules and dependencies it needs
    ],
    output: {
        path: path.resolve('./assets/bundles/'),
        filename: '[name]-[hash].js',
    }
    ,
    node: {
        console: true,
        fs: 'empty'
    }
    ,
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        }),
        new BundleTracker({filename: './webpack-stats.json'}),
        new webpack.BannerPlugin('Pqbq Banner!!!! todo'),
        new HtmlWebpackPlugin({
            template: __dirname + '/assets/index.tmpl.html'
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new Clean(['assets/bundles'])
    ],
    module: {
        preloaders: [
            {
                test: /\.js/,
                loader: 'eslint'
            }
        ],
        loaders: [
            {
                test: /\.js[x]?$/,
                loader: 'babel',
                exclude: /(node_modules|bower-components)/,
                query: {
                    presets: ['es2015', 'stage-0']
                }
            },
            {
                test: /\.json$/,
                loader: 'json-loader'
            },
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'node_modules/mapbox-gl/js/render/shaders.js'),
                loader: 'transform/cacheable?brfs'
            },
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'node_modules/webworkify/index.js'),
                loader: 'worker'
            },
            // {
            //     test: /\.css$/,
            //     loader: 'style!css?modules!postcss'
            // },
            {
                test: /\.scss$/,
                loaders: ['style', 'css?sourceMap', 'sass?sourceMap']
            },
            // {test: /\.(woff2?|svg)$/, loader: 'url?limit=10000'},
            // {test: /\.(ttf|eot)$/, loader: 'file'},
            {test: /\.css$/, loader: 'style-loader!css-loader'},
            {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
            {test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000'},
            {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
            //   {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
            {test: /\.svg$/, loader: 'url?limit=8192!svgo'},
        ]
    }
    ,
    postcss: [
        require('autoprefixer')
    ],
    resolve: {
        modulesDirectories: ['node_modules', 'bower_components', bootstrapPath, sourcePath],
        extensions: ['', '.js', '.jsx', '.css'],
        alias: {
            webworkify: 'webworkify-webpack',
            '$': 'jquery',
            'jQuery': 'jquery'
        }
    }
    ,
    devServer: {
        contentBase: './assets',
        colors: true,
        historyApiFallback: true,
        inline: true,
        hot: true
    }
};

为了解决这个问题,我必须通过创建自己的material.scss文件来覆盖$image_path变量。我抓到了这个文件:

然后加上:

@import "./variables";
在顶端

在该文件中,我添加了以下行:

$image_path: '~material-design-lite/dist/images/' !default;

这并不能完全解决问题,但问题的一部分是实际url是
.svg?embed
,它与
测试
正则表达式不匹配。我也看到了同样的问题。尝试使用
/\.svg(\?嵌入)?$/
@pho3nixf1这是一个很好的观点!我试过了,但问题仍然存在(控制台输出相同)。这个正则表达式真的捕捉正确吗?@pho3nixf1re我检查过你的正则表达式,它应该捕捉到“.svg?embed”。请让我知道,如果你发现进一步的进展,解决这个问题!