只需要一些幫助,我就會因爲這場鬥爭而失去理智。我搜索了很多這類相同問題的帖子,但它不起作用,這就是我在這裏尋求幫助。Preact您可能需要一個合適的加載程序來處理這種文件類型
我目前正在運行的簡單反應的的WebPack-dev的服務器上,當我要建立的preact COMPAT我剛剛得到這個錯誤:
您可能需要適當的加載程序來處理此類文件在Client.jsx
這是文件:
Client.jsx
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
const renderClient =() => {
render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('app'),
);
};
renderClient();
個
webpack.config.js
const path = require('path');
const webpack = require('webpack');
const config = {
context: __dirname,
entry: './src/components/Client.jsx',
devtool: 'cheap-module-eval-source-map',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/',
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat',
},
},
devServer: {
publicPath: '/public/',
historyApiFallback: true,
},
stats: {
colors: true,
reasons: true,
chunks: false,
},
plugins: [new webpack.NamedModulesPlugin()],
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/,
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
include: [path.resolve('js'), path.resolve('node_modules/preact-compat/src')],
},
],
},
};
if (process.env.NODE_ENV === 'production') {
config.devtool = 'source-map';
config.plugins = [];
}
module.exports = config;
.babelrc
{
"plugins": [
["transform-react-jsx", { "pragma": "h" }],
[
"module-resolver",
{
"root": ["."],
"alias": {
"react": "preact-compat",
"react-dom": "preact-compat"
}
}
]
],
"presets": [
"react",
[
"env",
{
"targets": {
"browsers": "last 2 versions"
},
"loose": true,
"modules": false
}
]
],
"env": {
"test": {
"plugins": ["babel-plugin-transform-es2015-modules-commonjs"]
}
}
}
非常感謝你兄弟! –