Created
May 23, 2018 12:52
-
-
Save egorguscha/00d5473e965a89b5658f5a4df841e6b1 to your computer and use it in GitHub Desktop.
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 HTML_WEBPACK_PLUGIN = require('html-webpack-plugin'); | |
const MERGE = require('webpack-merge'); | |
const PUG = require('./webpack/pug'); | |
const DEVSERVER = require('./webpack/devserver'); | |
const CSS = require('./webpack/css'); | |
const FONTS = require('./webpack/fonts'); | |
const IMAGES = require('./webpack/images'); | |
const SPRITE_SVG = require('./webpack/svg-sprite'); | |
const PATHS = { | |
src: PATH.join(__dirname, 'src'), | |
build: PATH.join(__dirname, 'build'), | |
}; | |
function pugPages(name) { | |
return new HTML_WEBPACK_PLUGIN({ | |
filename: name + '.html', | |
chunks: [name, 'common'], | |
template: PATHS.src + '/pug/' + name + '.pug', | |
}); | |
} | |
const COMMON = MERGE([ | |
{ | |
entry: { | |
index: PATHS.src + '/pages/index.js', | |
home: PATHS.src + '/pages/home/home.js', | |
}, | |
output: { | |
path: PATHS.build, | |
filename: 'js/[name].js', | |
}, | |
resolve: { | |
alias: { | |
js: PATHS.src + '/js/app.js', | |
sass: PATHS.src + '/sass/main.scss', | |
}, | |
}, | |
optimization: { | |
splitChunks: { | |
cacheGroups: { | |
commons: { | |
name: 'common', | |
chunks: 'initial', | |
minChunks: 2, | |
}, | |
}, | |
}, | |
}, | |
plugins: [ | |
pugPages('index'), | |
pugPages('home'), | |
new WEBPACK.ProvidePlugin({ | |
$: 'jquery', | |
jQuery: 'jquery', | |
}), | |
], | |
}, | |
PUG(), | |
IMAGES(), | |
FONTS(), | |
SPRITE_SVG(), | |
]); | |
module.exports = function(env) { | |
if (env === 'production') { | |
return MERGE([ | |
COMMON, | |
CSS(), | |
]); | |
} | |
if (env === 'development') { | |
return MERGE([ | |
COMMON, | |
DEVSERVER(), | |
CSS(), | |
]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment