Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Last active November 20, 2017 16:15
Show Gist options
  • Select an option

  • Save andrIvash/9aebc27330483070df581781f9617109 to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/9aebc27330483070df581781f9617109 to your computer and use it in GitHub Desktop.
webpack config
{
"name": "webpack-workshop",
"version": "1.0.0",
"scripts": {
"server": "node ./server/index.js",
"build": "cross-env NODE_ENV=production webpack",
"dev": "webpack-dev-server --hot --inline"
},
"private": true,
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-lodash": "^3.2.11",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.1.1",
"css-hot-loader": "^1.3.3",
"css-loader": "^0.28.7",
"express": "^4.16.2",
"extract-text-webpack-plugin": "^3.0.2",
"style-loader": "^0.19.0",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {
"lodash": "^4.17.4",
"markdown": "^0.5.0",
"moment": "^2.19.1"
}
}
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const basicConfig = {
resolve: {
extensions: ['.js'],
modulesDirectories: [
'./node_modules/',
'./src'
]
},
entry: {
home: './src/Home/index.js',
feed: './src/Feed/index.js'
},
output: {
path: path.resolve(__dirname, 'public', 'assets'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: {
loader: 'css-loader',
options: {
minimize: true
}
}
})
},
{
test: /\.js/,
use: [
{
loader: 'babel-loader',
options: {
presets: [['env', {
"targets": {
"browsers": ["last 2 versions", "ie >= 11"]
}
}]],
plugins: ['lodash']
}
}
]
}
],
},
plugins: [
new ExtractTextPlugin('feed.css')
],
};
if (isProduction) {
basicConfig.plugins = basicConfig.plugins.concat([
new webpack.optimize.UglifyJsPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin({
'process.env.NODE_ENV': 'production',
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common'
})
]);
} else {
basicConfig.devServer = {
contentBase: path.join(__dirname, "public"),
publicPath: '/assets/',
compress: true,
port: 9000,
proxy: {
"/data": "http://localhost:3000"
},
};
basicConfig.module.rules[0].use = ['css-hot-loader'].concat(basicConfig.module.rules[0].use);
}
module.exports = basicConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment