React 【ES2015】+ Babel + Gulp + Webpack

React 【ES2015】+ Babel + Gulp + Webpacknode

var webpack = require("webpack");
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin("common.js");

module.exports = {
	entry: {//入口文件
		routes:"./src/routes.js"
	},
	output: {//打包輸出
		path:__dirname,
		filename:"[name].entry.js"
	},
	resolve: {//定義模塊路徑
		extensions:['','.js','jsx']
	},
	externals: {
      'React': 'window.React'
    },
	module: {//處理模塊
		loaders:[{
			test:/\.js$/,
			loader:'babel-loader',
			query:{
				presets:['es2015', 'react']
			}
		}, {
			test:/\.jsx$/,
			loader:'babel-loader',
			query:{
				presets:['es2015', 'react']
			}
		}]
	},
	plugins:[commonsPlugin]
};

package.jsonreact

{
  "name": "cnode.js",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "jso0",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.5.2",
    "babel-loader": "^6.2.2",
    "bootstrap": "^3.3.6",
    "gulp": "^3.9.1",
    "gulp-webpack": "^1.5.0",
    "localStorage": "^1.0.3",
    "react": "^0.14.7",
    "react-bootstrap": "^0.28.3",
    "react-dom": "^0.14.7",
    "react-router": "^2.0.0",
    "webpack": "^1.12.13"
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0"
  }
}

 

 

 

參考:webpack

babel 爲何沒能識別我 js 文件中的 jsx 語法?web

相關文章
相關標籤/搜索