I am trying to figure out how to create one webpack configuration file that works for converting both server (node.js) js and js client with es2015 preinstalled. Currently, I need to specifically set "target:" node "so that it processes files based on node correctly. If I do not, then webpack will perform a conversion based on" target: "web" by default. Then it reports errors because the imported mysql module obviously does not work for the Internet.
How can I merge both into the same configuration file so that the server and js client are converted separately? Or do I need separate configs?
Webpack.config.js example
'use strict'; var path = require('path'); var webpack = require('webpack'); module.exports = { target: 'node', resolve: { root: path.resolve(__dirname), extensions: ['', '.js'] }, entry: [ 'babel-polyfill', './index.js', ], output: { filename: 'bundle.js' }, module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015'] } } ] } };
Js code example
import 'babel-polyfill'; import mysql from 'mysql'; class Test { constructor () { } get read () { } };
javascript webpack babeljs
Geuis
source share