将 ReactDOMServer 与 Sass 一起使用时出现语法错误
Syntax Error while using ReactDOMServer with Sass
我在项目中使用 ReactDOMServer
和 Sass
时出现如下语法错误:
SyntaxError: /Users/ceyhun23/Sites/{project_name}/lib/components/common/Menu/Menu.scss: Unexpected character '#' (1:3)
0|server | > 1 | img#logo{
0|server | | ^
0|server | 2 | height: 100%;
0|server | 3 | }
webpack.config.js
:
const path = require('path');
const config = {
resolve: {
alias: {
Assets: path.resolve(__dirname, 'lib/assets/'),
}
},
entry: ['babel-polyfill', './lib/components/App.js'],
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.(png|jpg)$/i,
exclude: /node_modules/,
loader: 'url-loader',
include: path.resolve(__dirname, 'lib/assets/images')
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
}
};
module.exports = config;
这是我的服务器脚本 ExpressJs
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import App from './components/App';
const serverRender = () => {
return ReactDOMServer.renderToString(
<App />
);
};
export default serverRender;
Menu
组件是 App
组件的子组件,Menu.scss
导入如下:
import React from 'react';
import './Menu.scss';
export default class Menu extends React.Component {
render() {...}
}
最后 Menu.scss
:
img#logo{
height: 100%;
}
你有什么建议吗?你能告诉我,我的来源有什么问题吗?
谢谢!
我在项目中使用 ReactDOMServer
和 Sass
时出现如下语法错误:
SyntaxError: /Users/ceyhun23/Sites/{project_name}/lib/components/common/Menu/Menu.scss: Unexpected character '#' (1:3) 0|server | > 1 | img#logo{ 0|server | | ^ 0|server | 2 | height: 100%; 0|server | 3 | }
webpack.config.js
:
const path = require('path');
const config = {
resolve: {
alias: {
Assets: path.resolve(__dirname, 'lib/assets/'),
}
},
entry: ['babel-polyfill', './lib/components/App.js'],
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.(png|jpg)$/i,
exclude: /node_modules/,
loader: 'url-loader',
include: path.resolve(__dirname, 'lib/assets/images')
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
}
};
module.exports = config;
这是我的服务器脚本 ExpressJs
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import App from './components/App';
const serverRender = () => {
return ReactDOMServer.renderToString(
<App />
);
};
export default serverRender;
Menu
组件是 App
组件的子组件,Menu.scss
导入如下:
import React from 'react';
import './Menu.scss';
export default class Menu extends React.Component {
render() {...}
}
最后 Menu.scss
:
img#logo{
height: 100%;
}
你有什么建议吗?你能告诉我,我的来源有什么问题吗?
谢谢!