Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/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/4/json/14.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
Reactjs 修改css文件中的路径_Reactjs_React Router_Frontend - Fatal编程技术网

Reactjs 修改css文件中的路径

Reactjs 修改css文件中的路径,reactjs,react-router,frontend,Reactjs,React Router,Frontend,但是在使用npm安装构建之后 背景图像:url(“../lib/images/loader.apng”);正在转换为 背景图像:url(../../static/media/loader.21688046.apng) 请提出解决办法 下面是webpack.config.dev.js //@从弹出开始移除 /** *版权所有(c)2015年至今,Facebook,Inc。 *版权所有。 * *此源代码根据中的BSD样式许可证进行许可 *此源目录树的根目录中的许可证文件。额外补助金 *可以在同一目录

但是在使用npm安装构建之后

背景图像:url(“../lib/images/loader.apng”);正在转换为 背景图像:url(../../static/media/loader.21688046.apng)

请提出解决办法

下面是webpack.config.dev.js

//@从弹出开始移除 /** *版权所有(c)2015年至今,Facebook,Inc。 *版权所有。 * *此源代码根据中的BSD样式许可证进行许可 *此源目录树的根目录中的许可证文件。额外补助金 *可以在同一目录的专利文件中找到专利权的名称。 */ //@在弹出端移除

below is the css code
.loaderActive {
  position: relative;
  overflow: hidden;
  &:after {
    position: absolute;
    top: 0%;
    left: 0%;
    content: "";
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    background-image:url("../lib/images/loader.apng");
    background-repeat: no-repeat;
    background-position: center;
  }
}
“严格使用”;
var autoprefixer=require('autoprefixer');
var webpack=require('webpack');
var HtmlWebpackPlugin=require('html-webpack-plugin');
var CaseSensitivePathsPlugin=require('case-sensitive-path-webpack-plugin');
var InterpolateHtmlPlugin=require('react-dev-utils/InterpolateHtmlPlugin');
var watchmissingdemodulesplugin=require('react-dev-utils/watchmissingdemodulesplugin');
var getClientEnvironment=require('./env');
变量路径=需要('./路径');
//@从弹出开始移除
//“路径”在弹出后不使用-请参阅https://github.com/facebookincubator/create-react-app/issues/1174
var path=require('path');
//@在弹出端移除
//Webpack使用“publicPath”确定应用程序的服务来源。
//在发展中,我们始终从根本上服务。这使得配置更容易。
var publicPath='/';
//“publicUrl”与“publicPath”类似,但我们会将其提供给我们的应用程序
//作为'index.html'中的%PUBLIC_URL%和JavaScript中的'process.env.PUBLIC_URL'。
//省略尾随斜杠,因为%PUBLIC\u PATH%/xyz看起来比%PUBLIC\u PATH%xyz好。
var publicUrl='';
//获取要注入到我们的应用程序中的环境变量。
var env=getClientEnvironment(publicUrl);
//这是开发配置。
//它专注于开发人员体验和快速重建。
//生产配置是不同的,存在于单独的文件中。
module.exports={
//如果希望在DevTools中查看编译后的输出,则可能需要使用“eval”。
//请参阅中的讨论https://github.com/facebookincubator/create-react-app/issues/343.
devtool:“廉价模块源映射”,
//这些是我们应用程序的“入口点”。
//这意味着它们将是JS包中包含的“根”导入。
//前两个入口点为JS启用“热”CSS和自动刷新。
条目:[
//包括WebpackDevServer的备用客户端。客户端的作业是
//通过套接字连接到WebpackDevServer,并获得有关更改的通知。
//保存文件时,客户端将应用热更新(如果
//或刷新页面(如果是JS更改)
//如果出现语法错误,此客户端将显示语法错误覆盖。
//注意:我们使用的不是默认的WebpackDevServer客户端,而是自定义客户端
//为Create React应用程序用户带来更好的体验。您可以替换
//如果您更喜欢股票客户,请使用以下两行:
//require.resolve('webpack-dev-server/client')+“?/”,
//require.resolve('webpack/hot/dev server'),
require.resolve('react-dev-utils/webpackHotDevClient'),
//默认情况下,我们会提供一些多边形填充:
require.resolve(“./polyfills”),
//最后,这是您的应用程序代码:
path.appIndexJs
//我们最后包含应用程序代码,以便在
//初始化时,它不会炸毁WebpackDevServer客户端,并且
//更改JS代码仍然会触发刷新。
],
输出:{
//下一行未在dev中使用,但WebpackDevServer在没有它的情况下崩溃:
路径:path.appBuild,
//向输出中生成的require()添加/*filename*/注释。
是的,
//这不会生成真正的文件,它只是虚拟路径
//由开发中的WebpackDevServer提供服务。这是JS包
//包含来自所有入口点的代码,以及Webpack运行时。
文件名:“static/js/bundle.js”,
//这是应用服务的URL。我们在开发中使用“/”。
公共路径:公共路径
},
决心:{
//这允许您为Webpack应该查找模块的位置设置回退。
//我们在'PATH.js'中读取'NODE_PATH'环境变量,并在此处传递路径。
//我们使用'fallback'而不是'root',因为我们希望'node_modules'能够“赢”
//如果存在任何冲突。这与节点解决机制匹配。
// https://github.com/facebookincubator/create-react-app/issues/253
后退:路径。节点路径,
//这些是节点生态系统支持的合理默认值。
//我们还包括JSX作为通用组件文件扩展名,以支持
//尽管我们不建议使用某些工具,但请参见:
// https://github.com/facebookincubator/create-react-app/issues/290
扩展:['.js'、'.json'、'.jsx'、''],
别名:{
//支持本地Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
“反应本机”:“反应本机web”
}
},
//@从弹出开始移除
//从
//'react scripts'本身的目录,而不是项目目录。
解析加载程序:{
root:path.ownNodeModules,
moduleTemplates:['*-loader']
},
//@在弹出端移除
模块:{
//首先,运行门楣。
//在巴贝尔处理JS之前这样做很重要。
预紧器:[
{
测试:/\(js|jsx)$/,
加载器:“eslint”,
包括:path.appSrc,
}
],
装载机:[
//**添加/更新加载程序**
//“url”加载器处理所有资产,除非明确排除。
//“排除”列表*必须*随着加载程序扩展的每次更改而更新。
//添加新加载程序时,必须添加其“测试”`
'use strict';

var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
var getClientEnvironment = require('./env');
var paths = require('./paths');

// @remove-on-eject-begin
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
var path = require('path');
// @remove-on-eject-end

// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
var publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
var publicUrl = '';
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl);

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
module.exports = {
  // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
  // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
  devtool: 'cheap-module-source-map',
  // These are the "entry points" to our application.
  // This means they will be the "root" imports that are included in JS bundle.
  // The first two entry points enable "hot" CSS and auto-refreshes for JS.
  entry: [
    // Include an alternative client for WebpackDevServer. A client's job is to
    // connect to WebpackDevServer by a socket and get notified about changes.
    // When you save a file, the client will either apply hot updates (in case
    // of CSS changes), or refresh the page (in case of JS changes). When you
    // make a syntax error, this client will display a syntax error overlay.
    // Note: instead of the default WebpackDevServer client, we use a custom one
    // to bring better experience for Create React App users. You can replace
    // the line below with these two lines if you prefer the stock client:
    // require.resolve('webpack-dev-server/client') + '?/',
    // require.resolve('webpack/hot/dev-server'),
    require.resolve('react-dev-utils/webpackHotDevClient'),
    // We ship a few polyfills by default:
    require.resolve('./polyfills'),
    // Finally, this is your app's code:
    paths.appIndexJs
    // We include the app code last so that if there is a runtime error during
    // initialization, it doesn't blow up the WebpackDevServer client, and
    // changing JS code would still trigger a refresh.
  ],
  output: {
    // Next line is not used in dev but WebpackDevServer crashes without it:
    path: paths.appBuild,
    // Add /* filename */ comments to generated require()s in the output.
    pathinfo: true,
    // This does not produce a real file. It's just the virtual path that is
    // served by WebpackDevServer in development. This is the JS bundle
    // containing code from all our entry points, and the Webpack runtime.
    filename: 'static/js/bundle.js',
    // This is the URL that app is served from. We use "/" in development.
    publicPath: publicPath
  },
  resolve: {
    // This allows you to set a fallback for where Webpack should look for modules.
    // We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
    // We use `fallback` instead of `root` because we want `node_modules` to "win"
    // if there any conflicts. This matches Node resolution mechanism.
    // https://github.com/facebookincubator/create-react-app/issues/253
    fallback: paths.nodePaths,
    // These are the reasonable defaults supported by the Node ecosystem.
    // We also include JSX as a common component filename extension to support
    // some tools, although we do not recommend using it, see:
    // https://github.com/facebookincubator/create-react-app/issues/290
    extensions: ['.js', '.json', '.jsx', ''],
    alias: {
      // Support React Native Web
      // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
      'react-native': 'react-native-web'
    }
  },
  // @remove-on-eject-begin
  // Resolve loaders (webpack plugins for CSS, images, transpilation) from the
  // directory of `react-scripts` itself rather than the project directory.
  resolveLoader: {
    root: paths.ownNodeModules,
    moduleTemplates: ['*-loader']
  },
  // @remove-on-eject-end
  module: {
    // First, run the linter.
    // It's important to do this before Babel processes the JS.
    preLoaders: [
      {
        test: /\.(js|jsx)$/,
        loader: 'eslint',
        include: paths.appSrc,
      }
    ],
    loaders: [
      // ** ADDING/UPDATING LOADERS **
      // The "url" loader handles all assets unless explicitly excluded.
      // The `exclude` list *must* be updated with every change to loader extensions.
      // When adding a new loader, you must add its `test`
      // as a new entry in the `exclude` list for "url" loader.

      // "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
      // Otherwise, it acts like the "file" loader.
      {
        exclude: [
          /\.html$/,
          // We have to write /\.(js|jsx)(\?.*)?$/ rather than just /\.(js|jsx)$/
          // because you might change the hot reloading server from the custom one
          // to Webpack's built-in webpack-dev-server/client?/, which would not
          // get properly excluded by /\.(js|jsx)$/ because of the query string.
          // Webpack 2 fixes this, but for now we include this hack.
          // https://github.com/facebookincubator/create-react-app/issues/1713
          /\.(js|jsx)(\?.*)?$/,
          /\.css$/,
          /\.json$/,
          /\.gif$/
        ],
        loader: 'url',
        query: {
          limit: 10000,
          name: 'static/media/[name].[hash:8].[ext]'
        }
      },
      // Process JS with Babel.
      {
        test: /\.(js|jsx)$/,
        include: paths.appSrc,
        loader: 'babel',
        query: {
          // @remove-on-eject-begin
          babelrc: false,
          presets: [require.resolve('babel-preset-react-app')],
          // @remove-on-eject-end
          // This is a feature of `babel-loader` for webpack (not Babel itself).
          // It enables caching results in ./node_modules/.cache/babel-loader/
          // directory for faster rebuilds.
          cacheDirectory: true
        }
      },
      // "postcss" loader applies autoprefixer to our CSS.
      // "css" loader resolves paths in CSS and adds assets as dependencies.
      // "style" loader turns CSS into JS modules that inject <style> tags.
      // In production, we use a plugin to extract that CSS to a file, but
      // in development "style" loader enables hot editing of CSS.
      {
        test: /\.css$/,
        loader: 'style!css?importLoaders=1!postcss'
      },
      // JSON is not enabled by default in Webpack but both Node and Browserify
      // allow it implicitly so we also enable it.
      {
        test: /\.json$/,
        loader: 'json'
      },
      // "file" loader for svg
      {
        test: /\.gif$/,
        loader: 'file',
        query: {
          name: '../img/[name].[ext]'
        }
      }
      // ** STOP ** Are you adding a new loader?
      // Remember to add the new extension(s) to the "url" loader exclusion list.
    ]
  },
  // @remove-on-eject-begin
  // Point ESLint to our predefined config.
  eslint: {
    configFile: path.join(__dirname, '../eslintrc'),
    useEslintrc: false,
  },
  // @remove-on-eject-end
  // We use PostCSS for autoprefixing only.
  postcss: function() {
    return [
      autoprefixer({
        browsers: [
          '>1%',
          'last 4 versions',
          'Firefox ESR',
          'not ie < 9', // React doesn't support IE8 anyway
        ]
      }),
    ];
  },
  plugins: [
    // Makes some environment variables available in index.html.
    // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
    // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    // In development, this will be an empty string.
    new InterpolateHtmlPlugin(env.raw),
    // Generates an `index.html` file with the <script> injected.
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml,
    }),
    // Makes some environment variables available to the JS code, for example:
    // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
    new webpack.DefinePlugin(env.stringified),
    // This is necessary to emit hot updates (currently CSS only):
    new webpack.HotModuleReplacementPlugin(),
    // Watcher doesn't work well if you mistype casing in a path so we use
    // a plugin that prints an error when you attempt to do this.
    // See https://github.com/facebookincubator/create-react-app/issues/240
    new CaseSensitivePathsPlugin(),
    // If you require a missing module and then `npm install` it, you still have
    // to restart the development server for Webpack to discover it. This plugin
    // makes the discovery automatic so you don't have to restart.
    // See https://github.com/facebookincubator/create-react-app/issues/186
    new WatchMissingNodeModulesPlugin(paths.appNodeModules)
  ],
  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};