问题描述
在使用 angularJS
作为客户端之前,我是 ReactJS
的新手.但是现在我想将其与 SpringMVC
上的当前应用程序集成.现在,我想将 ReactJS
集成为客户端,而不是 angularJS
,请帮助我.如果有任何示例,请帮忙.我正在使用 eclipse ide
.
I am a new to ReactJS
, before I used angularJS
for my client side. But now I want to integrate it with the present application on SpringMVC
. Now I want to integrate ReactJS
as client side instead of angularJS
, please help me. If there is any example please help. I am using eclipse ide
.
推荐答案
尝试创建视图(jsp/html/xhtml)并将UI构建输出链接到该视图.您可以将 webpack 用作UI(React)的构建工具,该工具将返回捆绑文件.
Try to create a view(jsp/html/xhtml) and link the UI build output to that. you may use webpack as a build tool for UI(React) which will return bundle file.
然后可以使用脚本标签将其包含在内进行查看.请注意,您可以使用webpack-dev-server进行UI开发,并尝试使用Proxy来使用spring-mvc服务.这是推荐的方式.如果您将 Maven 用作Java的构建工具,则可以使用包含webapp下所有JS的文件夹.
Then it can be included to view using script tag. Please note you can use webpack-dev-server for UI development and try to use Proxy to consume the spring-mvc service. Its a recommended way. A folder containing all the JS under webapp can be used if your using Maven as build tool for java.
webpack参考: https://webpack.js.org/
webpack reference : https://webpack.js.org/
样本 Webpack.config.js 供参考.
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
main: './src/scripts/main.js',
engine: './src/scripts/engine/Engine.js',
debugger: './src/scripts/debug/Debugmain.js',
client: './src/scripts/clientcode/Client.js'
},
output: {
path: path.resolve('./dist/client'),
filename: '[name].js',
publicPath: '/dist/client/',
chunkFilename: '[name].js'
},
devtool: 'inline-sourcemap',
cache: true,
resolve: {
alias: { ByteBuffer: 'bytebuffer' }
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'react-hot-loader'
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['react', 'es2015'],
compact: false
}
},
{
enforce: 'pre',
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: [path.join(__dirname, './src', 'scripts')],
loader: 'eslint-loader'
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
loader: 'css-loader?sourceMap!less-loader?sourceMap'
})
},
{
test: /\.(eot|woff|woff2|ttf|otf|png|jpg)$/,
loader: 'file-loader?name=images/[name].[ext]'
}
]
},
devServer: {
port: 8080,
stats: 'errors-only',
proxy: {
'/api': {
target: 'http://localhost:20404', //http://localhost:20403/',
secure: false
}
},
historyApiFallback: {
index: 'debug.html'
}
},
plugins: [
new ExtractTextPlugin({
filename: './styles/main.css',
allChunks: true
})
],
resolve: {
modules: ['src/scripts', 'node_modules'],
extensions: ['.jsx', '.js'],
unsafeCache: true,
alias: {
components: path.resolve(__dirname, 'src', 'scripts', 'components'),
routes: path.resolve(__dirname, '.', 'routes'),
draggable_tab: path.resolve(__dirname, 'src', 'scripts', 'lib'),
utils: path.resolve(__dirname, 'src', 'scripts', 'utils'),
engine: path.resolve(__dirname, 'src', 'scripts', 'engine')
}
}
};
这篇关于如何在Eclipse中将ReactJ与Spring MVC集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!