Reactjs 网页包3:css加载程序样式加载程序错误
我收到以下错误:Reactjs 网页包3:css加载程序样式加载程序错误,reactjs,webpack,webpack-3,Reactjs,Webpack,Webpack 3,我收到以下错误: import React from 'react'; require('./app.css'); const App = () => <div>Hello from React</div>; export default App; const webpack = require('webpack'); const path = require('path'); const ExtractTextWebpackPlugin = require(
import React from 'react';
require('./app.css');
const App = () => <div>Hello from React</div>;
export default App;
const webpack = require('webpack');
const path = require('path');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'inline-source-map',
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3001',
'webpack/hot/only-dev-server',
'./client/index',
],
target: 'web',
./common/app.css模块解析失败时出错:
E:\universal starter\common\app.css意外标记(1:5)您可以
需要适当的加载程序来处理此文件类型
我的App.js文件:
import React from 'react';
require('./app.css');
const App = () => <div>Hello from React</div>;
export default App;
const webpack = require('webpack');
const path = require('path');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'inline-source-map',
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3001',
'webpack/hot/only-dev-server',
'./client/index',
],
target: 'web',
//为什么这是错误的&导致了问题
// embed styles in styles folder
{
test: /\.css$/,
use: ExtractTextWebpackPlugin.extract({
fallback: 'style-loader',
use: ['css-loader']
})
},
到目前为止,网页3上的帮助很少。 有什么想法吗? 谢谢试试这个: 在App.js文件中,替换
require('./App.css')代码>用于导入“/app.css”
// fonts
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
exclude: /node_modules/,
loader: 'url-loader?limit=1024&name=fonts/[name].[ext]'
},
// examine img file size
{
test: /\.(jpe?g|png|svg|gif)$/,
use: [{
loader: 'url-loader',
options: {
limit: 40000,
name: 'images/[name].[hash].[ext]',
}
},
{
loader: 'image-webpack-loader',
}
]
}
],
},
plugins: [
new ExtractTextWebpackPlugin('./css/styles.css'),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HTMLWebpackPlugin({
template: './client/template/index.html',
}),
new webpack.DefinePlugin({
'process.env': { BUILD_TARGET: JSON.stringify('client') },
}),
],
devServer: {
host: 'localhost',
port: 3001,
historyApiFallback: true,
hot: true,
},
output: {
path: path.join(__dirname, '.build'),
publicPath: 'http://localhost:3001/',
filename: 'client.js',
},
};