在我的 reactJS 应用程序中 - 我将所有 .scss 文件包含在一个 main.scss 文件中 - 在 src 文件夹中的样式文件夹下。我有以下 webpack 配置。尝试将 main.scss 文件直接包含在我的主要组件中 - 在我导入其他 scss 文件的“@import”处出现错误。如果我包含单独的 scss 文件样式很好 - 但是如何使用一个 main.scss 文件以及如何包含它?
错误:意外的令牌,预期的((1:8)
1 | @import '我的组件';
module.exports = {
entry: [
'webpack-hot-middleware/client',
path.resolve(__dirname, 'src'),
],
output: {
path: path.resolve(__dirname, 'src'),
filename: 'bundle.js',
publicPath: '/',
},
plugins: [
new ExtractTextPlugin('bundle.css', { allChunks: true }),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
WEBPACK: true,
},
}),
],
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
query: {
presets: ['react-hmre'],
},
},
include: path.resolve(__dirname, 'src'),
},
{
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
'css-loader',
'sass-loader?outputStyle=expanded'.
]
}),
test: /\.scss$/,
exclude: /node_modules/
}
],
},
};
index.js
import React from 'react';
import { render } from 'react-dom';
import { createBrowserHistory } from 'history';
import { ConnectedRouter, routerMiddleware } from 'react-router-redux';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import App from './components/homepage';
import reducers from './reducers';
import '../styles/main.scss';
const history = createBrowserHistory();
const store = createStore(reducers, applyMiddleware(routerMiddleware(history)));
render(
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>
, document.getElementById('app'));
if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept();
module.hot.accept('./reducers', () => {
const nextRootReducer = require('./reducers').default; // eslint-disable-line global-require
store.replaceReducer(nextRootReducer(store.asyncReducers));
});
}