이 작업을 위해 WebPack을 사용할 것을 강력히 권장합니다.
루트 디렉토리에 webpack.config.js 파일을 만듭니다 어쩌면 당신의 코드가 일부 변경이 필요하지만이 아이디어입니다 :
const webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var pkgBower = require('./package.json');
module.exports = {
target: "web",
devtool: "source-map",
node: {
fs: "empty"
},
entry: {
'app': path.join(__dirname, 'react-app', 'Index.jsx')
},
resolve: {
modules: [__dirname, 'node_modules', 'bower_components'],
extensions: ['*','.js','.jsx', '.es6.js']
},
output: {
path: path.join(__dirname, 'public', 'src'),
filename: '[name].js'
},
resolveLoader: {
moduleExtensions: ["-loader"]
},
module: {
loaders: [
{
test: /jquery\.flot\.resize\.js$/,
loader: 'imports?this=>window'
},
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react', 'stage-0'],
compact: false
}
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
loader: 'url?prefix=font/&limit=10000'
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url?limit=10000'
},
{
test: /\.scss$/,
loader: 'style!css!sass?outputStyle=expanded'
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
new CopyWebpackPlugin([{
from: 'img',
to: 'img',
context: path.join(__dirname, 'react-app')
}, {
from: 'server',
to: 'server',
context: path.join(__dirname, 'react-app')
}, {
from: 'fonts',
to: 'fonts',
context: path.join(__dirname, 'react-app')
}]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
mangle: true,
sourcemap: false,
beautify: false,
dead_code: true
}),
new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/)
]
};
가 그런 반응 폴더에서 루트 디렉토리에 응용 프로그램을 넣어 -app/당신의 구성 요소는 해당 폴더 안에 갈 수 있습니다 : 예를 들어
파일을 [Index.jsx]
import React from 'react';
import ReactDOM from 'react-dom';
class Index extends Component {
render() {
return (<h1> hello world! < /h1>)
}
}
ReactDOM.render(< Index/> , document.getElementById('example'));
는이 산업을 수출 할 필요가 없습니다 구성 요소 파일의 끝에 기본 ComponentName 내보내기를 사용해야하는 경우를 대비하여.
다음 단계는 루트 파일에 (내가 AdonisJS 4를 사용하고 있습니다)하지만 ((.njk, 또는 .edge) 버전 3.x를
다음
Route.any("*", ({ view, response }) => (
view.render('index')
))
색인 매우 유사하다 파일 자원에서/전망) 같은 것을 보일 것입니다 :
<html>
<head>
<link rel="stylesheet" href="/src/styles.css">
<script type="text/javascript" src="/src/app.js"></script>
</head>
<body>
<div id="example"></div>
</body>
</html>
- 당신은 NPM 또는 원사, 와 일부 NPM/패키지를 설치하고 다른 터미널 창 또는 탭에서 실행 기억할 필요가 을
webpack -d --watch --progress
감사합니다.
콘솔에 오류가 있습니까? (< h1 > hello world! < /h1>) 또는'ReactDOM.render (< Index/> ...'는 전혀 문제가되지 않습니다.) – Nope
SyntaxError :이 줄에 구문 표현 오류가 있습니다. ')'가 반환됩니다 (< h1 > 안녕하세요! < /h1>) –
여기 있습니다. 구문 오류를 수정하면 잘 수행 할 수 있습니다. 나는 그들이 문자열이어야한다고 생각한다. 또한'ReactDOM.render (...)'의 경우 [** Documentation **] (https://reactjs.org/docs/react- dom.html # render)를 사용합니다. – Nope