Skip to content

Instantly share code, notes, and snippets.

@vcarl
Last active October 27, 2016 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcarl/722651191cd857b1b576c2244dc60c33 to your computer and use it in GitHub Desktop.
Save vcarl/722651191cd857b1b576c2244dc60c33 to your computer and use it in GitHub Desktop.
Sample webpack 2 config
{
"name": "jstest",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
},
"devDependencies": {
"babel": "^6.5.2",
"babel-loader": "^6.2.5",
"babel-cli": "^6.14.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-preset-es2015": "^6.9.4",
"webpack": "^2.1.0-beta.22"
}
}
const webpack = require('webpack');
const path = require('path');
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
module.exports = {
devtool: isProd? 'source-map' : 'eval',
context: path.join(__dirname, './src'),
entry: {
js: './index.js'
},
output: {
path: path.join(__dirname, './'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules|\.spec\.)/,
loader: 'babel-loader'
}
]
},
resolve: {
modules: [
'node_modules',
path.join(__dirname, './src')
]
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
isProd? new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true
}): null,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
PORT: JSON.stringify(process.env.PORT || 8080)
}
})
].filter(x => x != null)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment