Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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 触控笔无法与React一起使用_Css_Reactjs_Web Applications_Stylus - Fatal编程技术网

Css 触控笔无法与React一起使用

Css 触控笔无法与React一起使用,css,reactjs,web-applications,stylus,Css,Reactjs,Web Applications,Stylus,我正在帮助创建一个网络应用程序,我们最近切换到了触控笔和react。我已经重写了所有的StylusLang文件并编写了一些react,但是react根本没有被设置样式。下面是组件 import React, { Component } from 'react' import Icon from 'react-component-bytesize-icons' class CoursesCard extends Component { render() { const d

我正在帮助创建一个网络应用程序,我们最近切换到了触控笔和react。我已经重写了所有的StylusLang文件并编写了一些react,但是react根本没有被设置样式。下面是组件

import React, { Component } from 'react'
import Icon from 'react-component-bytesize-icons'

class CoursesCard extends Component {
    render() {
        const divStyle = {
            backgroundImage : '/assets/img/animatingCourse.jpg'
        }

        return (
          <div className='CoursesCard' style={divStyle}>
            <div className='CardOverlay'>
              <h3>What the courses is called?</h3>
              <p>Last Checed</p>
              <p>Users online</p>
            </div>
          </div>
        )
    }
}

export default CoursesCard

}React与手写笔毫无关系

我想你是用Webpack作为捆绑包的选择。如果是这样,您必须配置Webpack,使其了解如何处理
.styl
文件(或使用的任何文件扩展名)

Webpack有加载程序的概念-加载程序加载文件,以某种方式对其进行转换,并向下推送输出


您需要添加手写笔加载程序。要做到这一点,请看一下这个插件的

React与手写笔没有任何关系

我想你是用Webpack作为捆绑包的选择。如果是这样,您必须配置Webpack,使其了解如何处理
.styl
文件(或使用的任何文件扩展名)

Webpack有加载程序的概念-加载程序加载文件,以某种方式对其进行转换,并向下推送输出


您需要添加手写笔加载程序。要做到这一点,请看一下这个插件的

在React中使用手写笔需要一个类似捆绑包的网页包。我经常使用Stylus+React,所以我可以提供帮助,但你的问题并没有告诉我你是否设置了网页包和npm或纱线

因为我看不到你的完整版本,我可以分享我的版本,也许这会有所帮助。这是最接近我可以帮助你一步一步,而不知道更多关于你目前的建设。希望这有帮助

假设您已经设置了Webpack和npm,并且您的项目已经有一个package.json文件

  • 在终端中运行这些命令
  • npm安装纱线

    纱线初始

    yarn add poststylus autoprefixer-stylus autoprefixer
    
    css加载程序poststylus sass加载程序样式加载程序stylus加载程序

  • 使您的webpack.config.js与此类似

    const path = require('path');
    const postStylus = require('poststylus');
    const webpack = require('webpack');
    
    module.exports = {
      context: __dirname,
      entry: [
        './source/ClientApp.jsx',
        'react-hot-loader/patch',
        'webpack-dev-server/client?http://localhost:8080/',
        'webpack/hot/only-dev-server',
      ],
      devtool: 'cheap-eval-source-map',
      output: {
        path: path.join(__dirname, 'public'),
        filename: 'bundle.js',
        publicPath: '/public/',
        hotUpdateChunkFilename: 'hot/hot-update.js',
        hotUpdateMainFilename: 'hot/hot-update.json'
      },
      devServer: {
        hot: true,
        publicPath: '/public/',
        historyApiFallback: true,
      },
      watch: true,
      plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(),
        // new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.LoaderOptionsPlugin({
           options: {
            stylus: {
              preferPathResolver: 'webpack',
            },
           }
         }),
      ],
      resolve: {
        extensions: ['.js', '.jsx', '.json', '.styl'],
        modules: [
          path.resolve('./source'),
          path.resolve('./node_modules'),
        ],
      },
      stats: {
        colors: true,
        reasons: true,
        chunks: true,
      },
      module: {
        rules: [
          {
            enforce: 'pre',
            test: /\.js$/,
            loader: 'eslint-loader',
            exclude: /node_modules/,
          },
          {
            test: /\.jsx?$/,
            loader: 'babel-loader',
          },
          {
            test: /\.styl$/,
            use: [
              'style-loader',
              'css-loader',
              {
                loader: 'stylus-loader',
                options: {
                  use: [
                    postStylus(['autoprefixer']),
                  ],
                  modules: true,
                },
              },
            ],
            exclude: /node_modules/,
          },
        ],
      },
    };
    
  • 这是我的整个package.json,如果您需要它作为参考

    {
      "scripts": {
        "lint": "eslint **/*.{js,jsx} --quiet",
        "clean": "rm -r public/bundle.js",
        "build": "rm -r public/bundle.js && webpack",
        "dev": "webpack-dev-server --watch --progress --colors",
        "watch": "webpack --watch"
      },
      "dependencies": {
        "autoprefixer": "^7.1.2",
        "autoprefixer-stylus": "^0.14.0",
        "axios": "^0.16.2",
        "babel-core": "^6.25.0",
        "babel-eslint": "^7.2.3",
        "babel-loader": "^7.1.1",
        "babel-plugin-dynamic-import-node": "^1.0.2",
        "babel-plugin-dynamic-import-webpack": "^1.0.1",
        "babel-plugin-syntax-dynamic-import": "^6.18.0",
        "babel-plugin-transform-class-properties": "^6.24.1",
        "babel-plugin-transform-decorators-legacy": "^1.3.4",
        "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
        "babel-preset-airbnb": "^2.4.0",
        "babel-preset-env": "^1.6.0",
        "babel-preset-react": "^6.24.1",
        "babel-register": "^6.24.1",
        "concurrently": "^3.5.0",
        "css-loader": "^0.28.4",
        "d3": "^4.10.0",
        "enzyme": "^2.9.1",
        "eslint": "3.19.0",
        "eslint-config-airbnb": "^15.0.2",
        "eslint-config-airbnb-base": "^11.2.0",
        "eslint-config-react": "^1.1.7",
        "eslint-loader": "^1.9.0",
        "eslint-plugin-import": "^2.7.0",
        "eslint-plugin-jsx-a11y": "^5.0.3",
        "eslint-plugin-react": "^7.1.0",
        "express": "^4.15.3",
        "extract-text-webpack-plugin": "^3.0.0",
        "firebase": "^4.2.0",
        "firebase-tools": "^3.9.2",
        "json-loader": "^0.5.7",
        "node-sass": "^4.5.3",
        "nodemon": "^1.11.0",
        "poststylus": "^0.2.3",
        "prop-types": "^15.5.10",
        "react": "^15.6.1",
        "react-date-range": "^0.9.4",
        "react-dom": "^15.6.1",
        "react-hot-loader": "3.0.0-beta.6",
        "react-router-dom": "^4.1.2",
        "react-test-renderer": "^15.6.1",
        "resolve-url-loader": "^2.1.0",
        "sass-loader": "^6.0.6",
        "sort-package-json": "^1.7.0",
        "style-loader": "^0.18.2",
        "stylus": "^0.54.5",
        "stylus-loader": "^3.0.1",
        "webpack": "2.6.1",
        "webpack-combine-loaders": "^2.0.3",
        "webpack-dev-middleware": "^1.11.0",
        "webpack-dev-server": "^2.6.1",
        "webpack-hot-middleware": "^2.18.2"
      },
    }
    

  • 在React中使用手写笔需要一个类似捆绑包的网页包。我经常使用Stylus+React,所以我可以提供帮助,但你的问题并没有告诉我你是否设置了网页包和npm或纱线

    因为我看不到你的完整版本,我可以分享我的版本,也许这会有所帮助。这是最接近我可以帮助你一步一步,而不知道更多关于你目前的建设。希望这有帮助

    假设您已经设置了Webpack和npm,并且您的项目已经有一个package.json文件

  • 在终端中运行这些命令
  • npm安装纱线

    纱线初始

    yarn add poststylus autoprefixer-stylus autoprefixer
    
    css加载程序poststylus sass加载程序样式加载程序stylus加载程序

  • 使您的webpack.config.js与此类似

    const path = require('path');
    const postStylus = require('poststylus');
    const webpack = require('webpack');
    
    module.exports = {
      context: __dirname,
      entry: [
        './source/ClientApp.jsx',
        'react-hot-loader/patch',
        'webpack-dev-server/client?http://localhost:8080/',
        'webpack/hot/only-dev-server',
      ],
      devtool: 'cheap-eval-source-map',
      output: {
        path: path.join(__dirname, 'public'),
        filename: 'bundle.js',
        publicPath: '/public/',
        hotUpdateChunkFilename: 'hot/hot-update.js',
        hotUpdateMainFilename: 'hot/hot-update.json'
      },
      devServer: {
        hot: true,
        publicPath: '/public/',
        historyApiFallback: true,
      },
      watch: true,
      plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(),
        // new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.LoaderOptionsPlugin({
           options: {
            stylus: {
              preferPathResolver: 'webpack',
            },
           }
         }),
      ],
      resolve: {
        extensions: ['.js', '.jsx', '.json', '.styl'],
        modules: [
          path.resolve('./source'),
          path.resolve('./node_modules'),
        ],
      },
      stats: {
        colors: true,
        reasons: true,
        chunks: true,
      },
      module: {
        rules: [
          {
            enforce: 'pre',
            test: /\.js$/,
            loader: 'eslint-loader',
            exclude: /node_modules/,
          },
          {
            test: /\.jsx?$/,
            loader: 'babel-loader',
          },
          {
            test: /\.styl$/,
            use: [
              'style-loader',
              'css-loader',
              {
                loader: 'stylus-loader',
                options: {
                  use: [
                    postStylus(['autoprefixer']),
                  ],
                  modules: true,
                },
              },
            ],
            exclude: /node_modules/,
          },
        ],
      },
    };
    
  • 这是我的整个package.json,如果您需要它作为参考

    {
      "scripts": {
        "lint": "eslint **/*.{js,jsx} --quiet",
        "clean": "rm -r public/bundle.js",
        "build": "rm -r public/bundle.js && webpack",
        "dev": "webpack-dev-server --watch --progress --colors",
        "watch": "webpack --watch"
      },
      "dependencies": {
        "autoprefixer": "^7.1.2",
        "autoprefixer-stylus": "^0.14.0",
        "axios": "^0.16.2",
        "babel-core": "^6.25.0",
        "babel-eslint": "^7.2.3",
        "babel-loader": "^7.1.1",
        "babel-plugin-dynamic-import-node": "^1.0.2",
        "babel-plugin-dynamic-import-webpack": "^1.0.1",
        "babel-plugin-syntax-dynamic-import": "^6.18.0",
        "babel-plugin-transform-class-properties": "^6.24.1",
        "babel-plugin-transform-decorators-legacy": "^1.3.4",
        "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
        "babel-preset-airbnb": "^2.4.0",
        "babel-preset-env": "^1.6.0",
        "babel-preset-react": "^6.24.1",
        "babel-register": "^6.24.1",
        "concurrently": "^3.5.0",
        "css-loader": "^0.28.4",
        "d3": "^4.10.0",
        "enzyme": "^2.9.1",
        "eslint": "3.19.0",
        "eslint-config-airbnb": "^15.0.2",
        "eslint-config-airbnb-base": "^11.2.0",
        "eslint-config-react": "^1.1.7",
        "eslint-loader": "^1.9.0",
        "eslint-plugin-import": "^2.7.0",
        "eslint-plugin-jsx-a11y": "^5.0.3",
        "eslint-plugin-react": "^7.1.0",
        "express": "^4.15.3",
        "extract-text-webpack-plugin": "^3.0.0",
        "firebase": "^4.2.0",
        "firebase-tools": "^3.9.2",
        "json-loader": "^0.5.7",
        "node-sass": "^4.5.3",
        "nodemon": "^1.11.0",
        "poststylus": "^0.2.3",
        "prop-types": "^15.5.10",
        "react": "^15.6.1",
        "react-date-range": "^0.9.4",
        "react-dom": "^15.6.1",
        "react-hot-loader": "3.0.0-beta.6",
        "react-router-dom": "^4.1.2",
        "react-test-renderer": "^15.6.1",
        "resolve-url-loader": "^2.1.0",
        "sass-loader": "^6.0.6",
        "sort-package-json": "^1.7.0",
        "style-loader": "^0.18.2",
        "stylus": "^0.54.5",
        "stylus-loader": "^3.0.1",
        "webpack": "2.6.1",
        "webpack-combine-loaders": "^2.0.3",
        "webpack-dev-middleware": "^1.11.0",
        "webpack-dev-server": "^2.6.1",
        "webpack-hot-middleware": "^2.18.2"
      },
    }
    
  • 把我的答案签入