Skip to content

Instantly share code, notes, and snippets.

@egorguscha
Created May 23, 2018 12:52
Show Gist options
  • Save egorguscha/00d5473e965a89b5658f5a4df841e6b1 to your computer and use it in GitHub Desktop.
Save egorguscha/00d5473e965a89b5658f5a4df841e6b1 to your computer and use it in GitHub Desktop.
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