const Path = require('path'); const nodeExternals = require('webpack-node-externals'); //針對服務器端,對於require這樣的代碼進行與客戶端不一樣的處理 module.exports = { target: 'node', //針對服務器端,對於require這樣的代碼進行與客戶端不一樣的處理 mode: 'development', entry: './src/index.js', output: { filename: 'bundle.js', path: Path.resolve(__dirname, 'build') }, externals: [nodeExternals()], module: { rules: [{ test: /\.js?$/, loader: 'babel-loader', //須要安裝babel-loader babel-core exclude: /node-modules/, options: { presets: [ //編譯規則 'react', //須要安裝babel-preset-react 'stage-0', //用那個就須要安裝那個 babel-preset-stage-0 'es2015', //babel-preset-es2015 ['env', { targets: {browsers: ['last 2 versions']} }] //兼容全部瀏覽器最後的兩個版本 安裝babel-preset-env ] } }] } }
項目地址:git@github.com:longlongdan/Reactssr.gitnode