const path = require ('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const pug = require ('./webpack/pug');
const devserver = require('./webpack/devserver');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const sass = require('./webpack/sass');
const css = require('./webpack/css');
const extractCss = require('./webpack/css.extract');
const images = require('./webpack/images');
const files = require('./webpack/files');
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const copy = require('copy-webpack-plugin');
const PATHS = {
source: path.join(__dirname, 'source'),
build: path.join(__dirname, 'build')
};
const common= merge([
{
mode:'',
entry: {
'index': PATHS.source + '/pages/index/index.js',
},
output: {
path: PATHS.build,
publicPath: '',
filename: 'js/[name].js'
},
resolve:{
alias: {
'@': path.resolve(__dirname,'source'),
}
},
plugins:[
new HtmlWebpackPlugin({
filename:'index.html',
chunks: ['index', 'common'],
template: PATHS.source + '/pages/index/index.pug',
scriptLoading: 'defer',
}),
new MiniCssExtractPlugin(),
new OptimizeCssAssetsPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
],
optimization:{
splitChunks:{
chunks: 'all',
name: 'common'
}
},
devtool:'',
},
pug(),
images(),
files()
]);
module.exports = function(env){
common.mode = env;
if (env === 'production'){
common.devtool = false;
return merge([
{
plugins:[
new CleanWebpackPlugin(),
]
},
common,
extractCss(),
])
}
if (env === 'development'){
common.devtool = 'eveal-sourcemap';//Будет создаваться сорсмап
return merge([
common,
devserver(),
sass(),
css()
])
}
};