silverstripe-webpack/webpack.config.prod.js

140 lines
4.5 KiB
JavaScript
Raw Normal View History

2018-02-22 14:39:58 +01:00
/*
* Production assets generation
*/
2018-02-05 12:11:01 +01:00
const webpack = require('webpack');
2018-02-22 14:39:58 +01:00
const conf = require('./webpack.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
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');
2018-02-05 12:11:01 +01:00
module.exports = merge(common, {
devtool: '',
2018-02-05 12:11:01 +01:00
output: {
2019-04-11 00:15:29 +02:00
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
},
module: {
rules: [{
2018-04-24 07:44:56 +02:00
test: /\.s?css$/,
2018-02-05 12:11:01 +01:00
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [{
loader: 'css-loader',
options: {
sourceMap: false,
2018-04-24 07:44:56 +02:00
minimize: true
2018-02-05 12:11:01 +01:00
}
}, {
loader: 'postcss-loader',
options: {
sourceMap: false,
2018-02-05 12:11:01 +01:00
plugins: [
autoprefixer({
// If we want to use the same browser list for more tools
// this list should be moved to package.json
// https://evilmartians.com/chronicles/autoprefixer-7-browserslist-2-released
browsers: [
'ie >= 11',
'ie_mob >= 11',
'Safari >= 10',
'Android >= 4.4',
'Chrome >= 44', // Retail
'Samsung >= 4'
]
2018-02-22 14:39:58 +01:00
})
2018-02-05 12:11:01 +01:00
]
}
}, {
loader: 'resolve-url-loader'
}, {
loader: 'sass-loader',
options: {
sourceMap: false
2018-02-05 12:11:01 +01:00
}
}, ]
})
2018-02-08 19:16:34 +01:00
}, {
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
2018-02-22 14:39:58 +01:00
outputPath: 'fonts/',
publicPath: '../fonts/'
2018-02-08 19:16:34 +01:00
}
}]
2018-04-21 05:36:06 +02:00
}, {
test: /\.(ttf|otf|eot|svg|woff(2)?)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
publicPath: '../fonts/'
}
}]
2019-04-11 00:15:29 +02:00
}, {
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
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
2018-04-24 07:44:56 +02:00
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
2018-02-05 12:11:01 +01:00
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
2018-02-05 12:11:01 +01:00
comments: false
}),
new ExtractTextPlugin({
2018-02-22 14:39:58 +01:00
filename: 'css/[name].css',
2018-02-05 12:11:01 +01:00
allChunks: true
}),
2018-04-24 07:44:56 +02:00
2018-02-05 12:11:01 +01:00
new FaviconsWebpackPlugin({
2019-04-11 00:15:29 +02:00
logo: path.join(__dirname, conf.APPDIR, conf.SRC, 'favicon.png'),
2018-02-05 12:11:01 +01:00
prefix: '/icons/',
2019-04-11 00:15:29 +02:00
statsFilename: path.join(conf.APPDIR, conf.DIST, 'icons', 'iconstats.json'),
2018-02-05 12:11:01 +01:00
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: true,
favicons: true,
firefox: true,
opengraph: true,
twitter: true,
yandex: true,
windows: true
}
}),
],
});