2018-02-22 14:39:58 +01:00
|
|
|
/*
|
|
|
|
* Production assets generation
|
|
|
|
*/
|
|
|
|
|
2018-02-05 12:11:01 +01:00
|
|
|
const webpack = require('webpack');
|
2019-05-23 13:02:32 +02:00
|
|
|
const commonVariables = require('./webpack.configuration');
|
|
|
|
const conf = commonVariables.configuration;
|
2018-02-05 12:11:01 +01:00
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const common = require('./webpack.config.common.js');
|
2018-02-22 14:39:58 +01:00
|
|
|
|
2019-05-23 13:02:32 +02:00
|
|
|
const filesystem = require('fs');
|
2018-02-22 14:39:58 +01:00
|
|
|
const path = require('path');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
|
2018-04-24 07:44:56 +02:00
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
|
2019-10-20 03:00:05 +02:00
|
|
|
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2019-09-07 05:06:25 +02:00
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2019-05-23 13:02:32 +02:00
|
|
|
let plugins = [
|
2019-06-08 17:54:43 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
'NODE_ENV': JSON.stringify('production')
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true,
|
|
|
|
debug: false
|
|
|
|
}),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: 'css/[name].css',
|
|
|
|
allChunks: true
|
|
|
|
}),
|
2019-05-23 13:02:32 +02:00
|
|
|
|
2019-06-08 17:54:43 +02:00
|
|
|
new FaviconsWebpackPlugin({
|
|
|
|
title: 'Webpack App',
|
|
|
|
logo: path.join(__dirname, conf.APPDIR, conf.SRC, 'favicon.png'),
|
|
|
|
prefix: '/icons/',
|
|
|
|
emitStats: false,
|
|
|
|
persistentCache: true,
|
|
|
|
inject: false,
|
|
|
|
statsFilename: path.join(conf.APPDIR, conf.DIST, 'icons', 'iconstats.json'),
|
|
|
|
icons: {
|
|
|
|
android: true,
|
|
|
|
appleIcon: true,
|
|
|
|
appleStartup: true,
|
|
|
|
coast: true,
|
|
|
|
favicons: true,
|
|
|
|
firefox: true,
|
|
|
|
opengraph: true,
|
|
|
|
twitter: true,
|
|
|
|
yandex: true,
|
|
|
|
windows: true
|
|
|
|
}
|
|
|
|
}),
|
2019-09-07 05:06:25 +02:00
|
|
|
new OptimizeCssAssetsPlugin({
|
|
|
|
//assetNameRegExp: /\.optimize\.css$/g,
|
|
|
|
cssProcessor: require('cssnano'),
|
|
|
|
cssProcessorPluginOptions: {
|
|
|
|
preset: ['default', {
|
|
|
|
discardComments: {
|
|
|
|
removeAll: true
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
canPrint: true
|
|
|
|
}),
|
2019-05-23 13:02:32 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// add themes favicons
|
|
|
|
commonVariables.themes.forEach((theme) => {
|
2019-06-08 17:54:43 +02:00
|
|
|
const faviconPath = path.join(__dirname, theme, conf.SRC, 'favicon.png');
|
|
|
|
if (filesystem.existsSync(faviconPath)) {
|
|
|
|
plugins.push(new FaviconsWebpackPlugin({
|
|
|
|
title: 'Webpack App',
|
|
|
|
logo: faviconPath,
|
|
|
|
prefix: '/' + theme + '-icons/',
|
|
|
|
emitStats: false,
|
|
|
|
persistentCache: true,
|
|
|
|
inject: false,
|
|
|
|
statsFilename: path.join(conf.APPDIR, conf.DIST, theme + '-icons', 'iconstats.json'),
|
|
|
|
icons: {
|
|
|
|
android: true,
|
|
|
|
appleIcon: true,
|
|
|
|
appleStartup: true,
|
|
|
|
coast: true,
|
|
|
|
favicons: true,
|
|
|
|
firefox: true,
|
|
|
|
opengraph: true,
|
|
|
|
twitter: true,
|
|
|
|
yandex: true,
|
|
|
|
windows: true
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2019-05-23 13:02:32 +02:00
|
|
|
});
|
|
|
|
|
2018-02-05 12:11:01 +01:00
|
|
|
module.exports = merge(common, {
|
2019-06-08 17:54:43 +02:00
|
|
|
mode: 'production',
|
|
|
|
optimization: {
|
|
|
|
namedModules: true, // NamedModulesPlugin()
|
|
|
|
splitChunks: { // CommonsChunkPlugin()
|
|
|
|
name: 'vendor',
|
|
|
|
minChunks: 2
|
2019-05-23 14:44:10 +02:00
|
|
|
},
|
2019-06-08 17:54:43 +02:00
|
|
|
noEmitOnErrors: true, // NoEmitOnErrorsPlugin
|
|
|
|
concatenateModules: true, //ModuleConcatenationPlugin
|
|
|
|
minimizer: [
|
2019-10-20 03:00:05 +02:00
|
|
|
new TerserPlugin({
|
|
|
|
parallel: true,
|
|
|
|
sourceMap: false,
|
|
|
|
terserOptions: {
|
|
|
|
parse: {
|
|
|
|
ecma: 8,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
ecma: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2019-06-08 17:54:43 +02:00
|
|
|
]
|
|
|
|
},
|
2019-05-23 14:44:10 +02:00
|
|
|
|
2019-06-08 17:54:43 +02:00
|
|
|
devtool: '',
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2019-06-08 17:54:43 +02:00
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, conf.APPDIR, conf.DIST),
|
|
|
|
filename: path.join('js', '[name].js'),
|
|
|
|
publicPath: path.join(conf.APPDIR, conf.DIST),
|
|
|
|
},
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2019-06-08 17:54:43 +02:00
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: "style-loader",
|
|
|
|
use: [{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
2019-08-12 11:13:01 +02:00
|
|
|
sourceMap: false
|
2019-06-08 17:54:43 +02:00
|
|
|
}
|
2018-02-08 19:16:34 +01:00
|
|
|
}, {
|
2019-06-08 17:54:43 +02:00
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: false,
|
|
|
|
plugins: [
|
2019-11-25 08:00:33 +01:00
|
|
|
autoprefixer()
|
2019-06-08 17:54:43 +02:00
|
|
|
]
|
|
|
|
}
|
2018-04-21 05:36:06 +02:00
|
|
|
}, {
|
2019-06-08 17:54:43 +02:00
|
|
|
loader: 'resolve-url-loader'
|
2019-04-11 00:15:29 +02:00
|
|
|
}, {
|
2019-06-08 17:54:43 +02:00
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: false
|
|
|
|
}
|
2019-04-11 00:15:29 +02:00
|
|
|
}, ]
|
2019-06-08 17:54:43 +02:00
|
|
|
})
|
|
|
|
}, {
|
|
|
|
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
|
|
|
|
use: [{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/',
|
|
|
|
publicPath: '../fonts/'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
test: /\.(ttf|otf|eot|svg|woff(2)?)$/,
|
|
|
|
use: [{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/',
|
|
|
|
publicPath: '../fonts/'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
test: /\.(png|jpg|jpeg|gif|svg)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'img/',
|
|
|
|
publicPath: '../img/'
|
|
|
|
/*,
|
|
|
|
name(file) {
|
|
|
|
//return 'public/[path][name].[ext]';
|
|
|
|
return '[hash].[ext]';
|
|
|
|
},*/
|
|
|
|
},
|
|
|
|
}, ]
|
|
|
|
},
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2019-06-08 17:54:43 +02:00
|
|
|
plugins: plugins,
|
2018-07-02 03:54:18 +02:00
|
|
|
});
|