我已经使用以下代码导入 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)