在反应组件中导入scss

时间:2017-11-10 14:09:13

标签: javascript reactjs sass ecmascript-6

我有这个webpack.config文件:

const path = require('path')

var config = {
   entry: './src/index.js',
   output: {
      path:'/',
      filename: 'bundle.js',
   },
   devServer: {
      inline: true,
      port: 8080,
      historyApiFallback: {
        index: 'index.html'
      }
   },
   module: {
     loaders: [
       {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
        presets: ['es2015', 'react']
        }
      },
      {
        test: /\.scss$/,
        loaders: ["style", "css", "sass"]
      },
    ]
   },
    resolve: {
        modules: [path.resolve(__dirname, "src"), "node_modules"]
    }
}
module.exports = config;

当我想导入样式时,我收到此错误:

未捕捉错误:

  

找不到模块" ./ style.scss" at webpackMissingModule(bundle.js:77680)at object.defineProperty.value(bundle.js:77680)at webpack_require(bundle.js:20)at object.defineProperty.value(bundle.js:77611)at webpack_require(bundle.js) :20)在Object.defineProperty.value(bundle.js:77047)at at webpack_require(bundle.js:20)at object.defineProperty.value(bundle.js:50608)at webpack_require(bundle.js:20)at Object。 defineProperty.value(bundle.js:50310)

这是组件:

...
import './style.scss';

class Solution extends Component {
  render() {
    return (
      ...
    )
  }
}

export default Solution;

scss文件在同一文件夹中有组件。

0 个答案:

没有答案