const webpack = require('webpack');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const path = require('path');
const HmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const PATHS = {
source: path.join(__dirname, 'src'),
build: path.join(__dirname, 'build')
};
const common = {
entry: PATHS.source + '/js/index.js',
output: {
path: PATHS.build,
filename: 'js/bundle.js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader?-minimize', 'sass-loader']
})
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader?-minimize',
options: {
minimize: true
}
}
]
})
},
{
test: /\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'file-loader',
options: {
name: 'img/[name].[ext]'
}
},
{
test: /\.html$/,
loader: 'html-loader'
}
],
loaders: [
{
test: /\.html$/,
loader: ['file-loader', 'html-loader']
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: ['file-loader'],
options: {
name: 'img/[name].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: ['file-loader'],
options: {
name: 'fonts/[name].[ext]'
}
},
{
test: /\.css$/,
loader: 'css-loader?-minimize'
},
{
test: /\.scss$/,
loader: 'css-loader!sass-loader',
}
]
},
plugins: [
new HmlWebpackPlugin({
template: './src/templates/index.html',
filename: 'index.html'
}),
new HmlWebpackPlugin({
template: './src/templates/benefits.html',
filename: 'benefits.html'
}),
new ExtractTextPlugin('css/bundle.css'),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
include: /\.min\.js$/
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.min\.css$/,
cssProcessorOptions: { discardComments: { removeAll: true } }
}),
new CopyWebpackPlugin([
{
from: './src/img',
to: 'img'
}
])
],
devtool: "source-map"
};
const devConfig = {
devServer: {
port: 9000,
contentBase: './src',
watchContentBase: true
}
};
module.exports = (env) => {
if (env === 'production') {
return common;
}
if (env === 'development') {
return Object.assign(
{},
common,
devConfig
);
}
};
Однако инклуд шаблонов не пашет все равно (( И JS с CSS не минифицируются (