Skip to content

Instantly share code, notes, and snippets.

@vcarl

vcarl/package.json

Last active Oct 27, 2016
Embed
What would you like to do?
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