webpack下的react配置檔案(熱替換)
阿新 • • 發佈:2019-02-01
webpack_dev_onfig.js配置檔案
const webpack = require('webpack'); const path = require("path"); const UglifyJSPlugin = require("uglifyjs-webpack-plugin"); const entry = "../app.js"; const outPutPath = "../public/build"; const outPutName = "build.js"; module.exports = { entry: path.resolve(__dirname, entry), output: { path: path.resolve(__dirname, outPutPath), filename: outPutName, publicPath: "/build/" }, devServer:{ port: 3030, contentBase: path.join(__dirname, '../views/'), publicPath: "/build/", inline: true, hot: true }, module:{ rules: [ { test:/\.jsx?$/, use:["babel-loader"], exclude: /node_modules/ }, { test: /\.(png|svg|jpg|gif)$/, use: { 'loader': 'file-loader', 'options':{ 'name':'[path][name].[ext]' } }, }, { test: /\.scss$/, use:['style-loader', 'css-loader?modules', 'sass-loader'] }, { test: /\.css$/, use:['style-loader', 'css-loader'] }, ] }, devtool:"inline-source-map", plugins: [ new UglifyJSPlugin(), new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin() ] };
.babelrc配置檔案
{ "presets":["env", "es2015", "react", "stage-0"], "plugins":[ "react-hot-loader/babel" ] }