score:5
Accepted answer
Hope you got your solution still answering here, it will help some people who needs to work react with grunt and babel
make sure first you have installed the followings:
npm install --save-dev grunt-babel babel-cli
Grunt plugin for Babel grunt-babel
npm install --save-dev babel-plugin-transform-es2015-modules-amd
npm install babel-preset-env --save-dev
npm install --save-dev babel-cli babel-preset-react
then add a grunt task/gruntfile as below :
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
babel: {
options: {
sourceMap: false,
presets: ["env", "react"],
plugins: ["transform-es2015-modules-amd"]
},
dist: {
files: [{
expand: true,
cwd: './src',
src: ['*.js'],
dest: './generated',
ext: '.js'
}]
}
}
});
grunt.loadNpmTasks('grunt-babel');
grunt.registerTask('default', ['babel']);
};
package.json
"devDependencies": {
"babel-cli": "^7.0.0-beta.3",
"babel-core": "7.0.0-alpha.19",
"babel-plugin-transform-es2015-modules-amd": "^7.0.0-alpha.19",
"babel-preset-env": "^2.0.0-beta.2",
"babel-preset-es2015": "7.0.0-alpha.19",
"babel-preset-react": "^7.0.0-alpha.19",
"grunt-babel": "^7.0.0",
}
Hope this helps.
EDITED
babel -> @babel
Since Babel 7 the Babel team switched to scoped packages, so you now have to use @babel/core instead of babel-core.
Your dependencies will need to be modified like so:
babel-cli -> @babel/cli. Ex: babel- with @babel/.
package.json will be look like below:
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"grunt-babel": "^8.0.0",
Source: stackoverflow.com
Related Query
- How to get React to work with Grunt and Babel?
- How do I get React to work with Babel and Gulp?
- How to get the simplest Material UI Select to work with React and Typescript?
- How to set up Babel 6 stage 0 with React and Webpack
- How to make react router work with static assets, html5 mode, history API and nested routes?
- how to work with react routers and spring boot controller
- How to get port forwarding to work with gatsby and vagrant or virtualbox
- How does Express and React Routes work on initial GET request from browser?
- How do I integrate React with a non-trivial AngularJS app and existing grunt configurations?
- How can I get React styleguidist to install correctly and get past the peer Dependency issues with react-simple-code-editor: React 16 & 17?
- How to get Emotion styled component in a React project to work with TypeScript?
- How to get ESLint to work React + Babel in Sublime Text 3 editor?
- How can I get a full working example with React 0.14 and Typescript 1.6.2 and Rails 4.2
- how does promise and useState really work in React with AWS Amplify?
- how to get images from mongo with axios and display them with react
- Could not get animation to work with AMP and React
- How Can I Get Form/Submit To Work with ReactStrap in a React functional component?
- How to get location pathname with React Router v5 and Hooks in React v16.13.1?
- How to download files with NodeJS backend and React frontend? (I get the files corrupted)
- How to get Google Analytics to work with React
- How can I get my product page to work on refresh with React -->Navigate?
- How to work with multiple checkboxes in react and collect the checked checkboxes
- How to get property based CSS styles to work with local rule references in Material-UI and JSS?
- How to get onClick in React to work on a single element with multiple siblings?
- What is inline-rendering in React router and how does it work with "render" inside a route/
- How do I get my navbar links to work in React JS after using react-routerdom and react bootstrap?
- How do I get type checking to work with React forwardRef
- How to make infinite scroll work with react and intersection api while lazily fetching data?
- How to get React running with Docker and nginx in Prod?
- How to get React setupProxy to work correctly with express.js
More Query from same tag
- How to convert CSV data to file type in Reactjs
- REACT with ts - checking props is null in tsx.view
- How to append a derived class to className - React
- ReactJS Code Splitting causes an error when loading Bootstrap through WebPack into Wordpress
- Why readonly keyword doesn't work with destructuring
- Button Copy to Clipboard window location href
- Structuring Redux state by domain?
- Unit Testing React Native: NativeModules.RNViewShot is undefined. Make sure the library is linked on the native side
- How should I go about adding an autoscroll to this Carousel that can be intervened by the user?
- Get state value without using useSelector
- Argument of type 'string' is not assignable to parameter of type... (React Hook Form) (TypeScript)
- Is there any way to render value on the basis of clicked item from an array in react using router?
- React Router will not take array as prop for a component
- REACT fetch properties from nested JSON
- Is it possible to toggle a class onclick if the button is in a different component
- React js TypeError: Cannot read property 'params' of undefined
- How to setState using RadioButton in ReactJs
- jsx if else shorthand to hide element
- Styling a Select element from react-select
- Better aproach for destructing Custom React Hooks with multiple returns?
- How do I define custom renderers for default Markdown elements using markdoc.io?
- ADD_SONG not added to PlayList
- e.target.value gives me this error whenever i enter more than one letter react Uncaught TypeError: Cannot read property 'value' of null"
- I am trying to access element inside modal(mui modal) using ref in react but reference to element is null
- reactjs how to filter / check if a any object in an array is present in another array of objects?
- React: Update element of array without rerendering other array elements
- React Ionic (v5): IonReactRouter & IonRouterOutlet Not Working as Expected
- How to override Box created by TabPanel in Material UI
- How to modify elements in React in scope of an instance of the component
- React App works perfectly on localhost, but errors out on Heroku