私はWebpack 2.5.1
,React 15.5.4
を使用しています。Webpack sass-loaderが、反応jsx文書にインポートされたsassスタイルシートをコンパイルできませんでした。予期しない文字 '@'
私はBootstrap
_utilities.scss
を反応プロジェクトに使用しようとしています。そして @import
ステートメントを使って他のsass部分をインポートするため、Webpackはドキュメントをコンパイルしようとするとエラーを報告します。
これは私のエントリmain.jsx
のコードのコードです。
import React from 'react';
import ReactDOM from 'react-dom';
import 'bootstrap/scss/_utilities.scss' // this is what causes the error
import '../stylesheets/components/gallery.scss'; // this one compiles properly if I comment the _utilities.scss import statement. It does not use @import notation.
class Gallery extends React.Component {
render(){
return (<div id="gallery" className="d-flex p-2">
<h1>using bootstrap flex-box</h1>
<p>Something something something!</p>
<button onClick={() => console.info('You clicked a button')}>Click Me!</button>
</div>)
}
}
これは私のwebpack.config.js
のコードです。
const path = require('path');
const webpack = require('webpack');
const CommonChunkPlugin =
require('./node_modules/webpack/lib/optimize/CommonsChunkPlugin');
module.exports = {
target: 'web',
watch: true,
devtool: 'source-map',
entry: {
main: './components/main.jsx',
vendor: ['react', 'react-dom']
},
output: {
path: path.resolve('..', 'build', 'js'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.(css|scss)$/,
exclude: /(node_modules)/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: { sourceMap: true }
},
{
loader: 'sass-loader',
options: { sourceMap: true }
}
]
},
{
test: /(\.js|\.jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader?cacheDirectory=true',
options: {
presets: ['es2015', 'react']
}
}
]
},
plugins: [
new CommonChunkPlugin({
name: 'vendor',
filename: 'vendor.js'
})
]
};
あなたが見ることができるように、私はcss
とscss
ファイルをコンパイルするstyle-loader
、css-loader
、およびsass-loader
を使用しています。
Webpack
の実行後に表示されるエラーメッセージです。
... _utilities.scss Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "utilities/align";
| @import "utilities/background"; ...
私はこのpostそして、この他のpostを見てきましたが、彼らは役立ちません。
私は間違っていることはありますか?どうすればこの問題を回避できますか?ありがとう。それは
ありがとうございました。私はそれを試みたが、うまくいかなかった。 – blaze
@toomuchdesign答えを使って解決しました。 – blaze