相关疑难解决方法(0)

如何在reactjs中删除导入的css

我已经使用以下代码导入 css

componentWillMount() {
    import('./patient-summary.css');
}
Run Code Online (Sandbox Code Playgroud)

未使用组件时如何从 react 中删除导入的 css。当我回到上一个屏幕时,这个 css 会在那里应用。任何的想法 ?

更新:: Webpack 配置

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: './src/index.js',
  output: {
  filename: 'bundle.js',
  path: path.resolve(__dirname, 'public/dist')
},
module: {
  rules: [
      {
          test: /\.js?$/, 
          loader: 'babel-loader',
          exclude: /node_modules/
      },
      {
          test: /\.css$/,
          use: [ 'style-loader', 'css-loader' ]
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        loader: "file-loader"
      }
      ,
      {
        test: /\.(png|jpeg|jpg|gif|svg)$/,
        loader: "file-loader"
      }
  ]
  },
  devServer: {
  contentBase: path.resolve(__dirname, "public"),
  historyApiFallback: true, …
Run Code Online (Sandbox Code Playgroud)

javascript css import reactjs redux

7
推荐指数
2
解决办法
4465
查看次数

标签 统计

css ×1

import ×1

javascript ×1

reactjs ×1

redux ×1