Last active
October 27, 2016 23:50
-
-
Save vcarl/722651191cd857b1b576c2244dc60c33 to your computer and use it in GitHub Desktop.
Sample webpack 2 config
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
{ | |
"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" | |
} | |
} |
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 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