Created
January 4, 2019 05:36
-
-
Save victorkurauchi/77cfb3c9c695282d3a6894fefb31e50e to your computer and use it in GitHub Desktop.
webpack config with client and server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const mode = process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'test' ? 'development' : 'production'; | |
const serverConfig = { | |
target: 'node', | |
mode: mode, | |
entry: __dirname + '/src/index.js', | |
devtool: 'inline-source-map', | |
resolve: { | |
extensions: [ '.js' ] | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.m?js$/, | |
exclude: /(node_modules)/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'] | |
} | |
} | |
} | |
] | |
}, | |
output: { | |
filename: 'weather.js', | |
path: path.resolve(__dirname, 'dist'), | |
library: 'weather', | |
libraryTarget: 'umd', | |
globalObject: 'typeof self !== \'undefined\' ? self : this' | |
} | |
}; | |
const clientConfig = { | |
target: 'web', | |
mode: mode, | |
entry: __dirname + '/src/index.js', | |
devtool: 'inline-source-map', | |
resolve: { | |
extensions: [ '.js' ] | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.m?js$/, | |
exclude: /(node_modules)/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'] | |
} | |
} | |
} | |
] | |
}, | |
output: { | |
filename: 'weather.min.js', | |
path: path.resolve(__dirname, 'dist'), | |
library: 'Weather', | |
libraryTarget: 'var' | |
} | |
}; | |
module.exports = [serverConfig, clientConfig]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment