Я создаю шаблон SSR, и когда я использую @ babebl / register и затем выполняю webpack (config), система сообщает об ошибке.Я пробовал @ babel / polyfill и @ babel / plugin-transform-runtime, но ни один из них не работал.
Версия (и) Babel: 7.4.3 Версия Node / npm: [например, Node 10.15.3 / npm6.4.1] ОС: окно 10
index.js:
require("ignore-styles");
require("@babel/register")({
ignore: [/\/(build|node_modules)\//],
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-syntax-dynamic-import", "dynamic-import-node"]
});
require("./server");
server.js
const config = require('../config/webpack.dev.config.js')
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware')
const reactRouter = require('react-router')
const StaticRouter = reactRouter.reactRouter;
const app = express()
const complier = webpack(config)
const PORT = 8090
...
app.use(webpackDevMiddleware(complier, {
publicPath: config.output.publicPath
}))
app.listen(PORT , function() {
console.log(`SSR running on port ${PORT }`);
})
webpack.dev.config.js
const paths = require('./paths')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: ['webpack-hot-middleware/client?reload=true', paths.appIndexJs],
output: {
path: paths.clientBuild,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: paths.publicPath
},
devtool: 'eval-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: "2",
targets: {
browsers: ['last 2 versions', 'ie >= 9'],
},
}],
'@babel/preset-react'
]
}
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new htmlWebpackPlugin({
template: './client/index.html',
filename: 'index.html'
})
]
}
Rep
https://github.com/xuchenchenBoy/ssr (Пожалуйста, выполните npm run dev: server и заметки о выпуске в server.js)