This my first experience on gulp. I try to import react-route-dom
in my index.jsx
. But when I try to import it, I faced with this error message :
'react-router-dom' is imported by projectMyAccount.Site\project.MyAccount.Site.Desktop\scripts\js\desktop\bundle\app.js, but could not be resolved – treating it as an external dependency No name was provided for external module 'react-router-dom' in options.globals – guessing 'reactRouterDom'
Index Jsx:
import Index from '../pages/MyAccount/Index';
import Support from '../pages/Support/Index';
import {BrowserRouter as Router, Route,Link} from 'react-router-dom';
class Pager extends React.Component {
constructor(props){
super(props);
}
render(){
<Router>
<div>
<ul>
<li><Link to="/test1">Home</Link></li>
<li><Link to="/about-us">About Use</Link></li>
</ul>
<hr/>
<Route path="/hesabim" component={Index}/>
<Route path="/about" component={Support}/>
</div>
</Router>
}
};
main gulp tasks:
gulp.task('es6', function () {
return gulp.src(filePath + '/scripts/js/**/*.js')
.pipe(babel())
.pipe(gulp.dest(filePath + '/scripts/js'));
});
gulp.task('react', function () {
return gulp.src(filePath + '/scripts/jsx/**/*.jsx')
.pipe(react({harmony: false, es6module: true}))
.pipe(gulp.dest(filePath + '/scripts/js/'));
});
gulp.task('create-app', function () {
return gulp.src([
filePath + '/Scripts/js/desktop/pages/Index.js'
])
.pipe(concatJs("hepsiburada.js"))
.pipe(gulp.dest(filePath + '/scripts/js/desktop/bundle'))
.pipe(rollup({
allowRealFiles: true,
"format": "iife",
"plugins": [
require("rollup-plugin-babel")({
"presets": [["es2015", { "modules": false }]],
"plugins": ["external-helpers"]
})
],
entry: filePath + '/scripts/js/desktop/bundle/app.js'
}))
.pipe(gulp.dest(filePath + '/build/scripts/'));
});
What is wrong? Do I have to import another packages for gulp? It is not clear for me. I can use it with unpkg package like this :
import Index from '../pages/MyAccount/Index';
import Support from '../pages/Support/Index';
class Pager extends React.Component {
constructor(props){
super(props);
}
render(){
const Router = ReactRouterDOM.BrowserRouter;
const Link = ReactRouterDOM.Link;
const Route = ReactRouterDOM.Route;
return (<Router>
<div>
<ul>
<li><Link to="/test1">Home</Link></li>
<li><Link to="/about-us">About Use</Link></li>
</ul>
<hr/>
<Route path="/hesabim" component={Index}/>
<Route path="/about" component={Support}/>
</div>
</Router>);
}
};
But I think it is not good for development for a long period. How can I implement it from node modules?