2019-12-10 19:11:31 +01:00
|
|
|
const SOURCEDIR = './src';
|
2019-10-20 04:40:30 +02:00
|
|
|
const COMPRESS = false;
|
|
|
|
|
2019-06-08 17:20:51 +02:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
2019-12-10 19:11:31 +01:00
|
|
|
const filesystem = require('fs');
|
|
|
|
|
2019-06-08 17:20:51 +02:00
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
2019-10-20 03:19:20 +02:00
|
|
|
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2020-01-22 10:49:07 +01:00
|
|
|
const ImageminPlugin = require('imagemin-webpack');
|
2020-01-23 03:09:36 +01:00
|
|
|
const ImageSpritePlugin = require('@a2nt/image-sprite-webpack-plugin');
|
2019-06-08 17:20:51 +02:00
|
|
|
|
2019-10-20 04:40:30 +02:00
|
|
|
const plugins = [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
2020-01-22 10:49:07 +01:00
|
|
|
NODE_ENV: JSON.stringify('production'),
|
|
|
|
},
|
2019-10-20 04:40:30 +02:00
|
|
|
}),
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: COMPRESS,
|
2020-01-22 10:49:07 +01:00
|
|
|
debug: false,
|
2019-10-20 04:40:30 +02:00
|
|
|
}),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: 'css/[name].css',
|
2020-01-22 10:49:07 +01:00
|
|
|
allChunks: true,
|
2019-10-20 04:40:30 +02:00
|
|
|
}),
|
|
|
|
/**/
|
|
|
|
new HtmlWebpackPlugin({
|
2020-01-22 10:49:07 +01:00
|
|
|
template: './src/index.html',
|
2019-10-20 04:40:30 +02:00
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (COMPRESS) {
|
2020-01-22 10:49:07 +01:00
|
|
|
plugins.push(
|
|
|
|
new OptimizeCssAssetsPlugin({
|
|
|
|
//assetNameRegExp: /\.optimize\.css$/g,
|
|
|
|
cssProcessor: require('cssnano'),
|
|
|
|
cssProcessorPluginOptions: {
|
|
|
|
preset: ['default'],
|
2019-12-17 21:36:38 +01:00
|
|
|
},
|
2020-01-22 10:49:07 +01:00
|
|
|
cssProcessorOptions: {
|
|
|
|
zindex: true,
|
|
|
|
cssDeclarationSorter: true,
|
|
|
|
reduceIdents: false,
|
|
|
|
mergeIdents: true,
|
|
|
|
mergeRules: true,
|
|
|
|
mergeLonghand: true,
|
|
|
|
discardUnused: true,
|
|
|
|
discardOverridden: true,
|
|
|
|
discardDuplicates: true,
|
|
|
|
discardComments: {
|
|
|
|
removeAll: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
canPrint: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
plugins.push(
|
|
|
|
new ImageminPlugin({
|
|
|
|
bail: false, // Ignore errors on corrupted images
|
|
|
|
cache: true,
|
|
|
|
filter: (source, sourcePath) => {
|
|
|
|
if (source.byteLength < 512000) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
imageminOptions: {
|
|
|
|
plugins: [
|
|
|
|
['gifsicle', { interlaced: true }],
|
|
|
|
['jpegtran', { progressive: true }],
|
|
|
|
['optipng', { optimizationLevel: 5 }],
|
|
|
|
[
|
|
|
|
'svgo',
|
|
|
|
{
|
|
|
|
plugins: [
|
|
|
|
{
|
|
|
|
removeViewBox: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-01-23 03:09:36 +01:00
|
|
|
|
|
|
|
plugins.push(
|
|
|
|
new ImageSpritePlugin({
|
|
|
|
exclude: /exclude|original|default-|icons|sprite/,
|
|
|
|
commentOrigin: false,
|
|
|
|
compress: true,
|
|
|
|
extensions: ['png'],
|
|
|
|
indent: '',
|
|
|
|
log: true,
|
|
|
|
//outputPath: path.join(__dirname, conf.APPDIR, conf.DIST),
|
|
|
|
outputFilename: 'img/sprite-[hash].png',
|
|
|
|
padding: 0,
|
|
|
|
}),
|
|
|
|
);
|
2019-10-20 04:40:30 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:11:31 +01:00
|
|
|
const includes = {};
|
|
|
|
|
2020-01-22 10:49:07 +01:00
|
|
|
const _addAppFiles = theme => {
|
2019-12-10 19:11:31 +01:00
|
|
|
const dirPath = path.resolve(__dirname, theme);
|
|
|
|
const themeName = path.basename(theme);
|
|
|
|
|
|
|
|
if (filesystem.existsSync(path.join(dirPath, 'js', 'app.js'))) {
|
|
|
|
includes['app'] = path.join(dirPath, 'js', 'app.js');
|
|
|
|
} else if (filesystem.existsSync(path.join(dirPath, 'scss', 'app.scss'))) {
|
|
|
|
includes['app'] = path.join(dirPath, 'scss', 'app.scss');
|
|
|
|
}
|
|
|
|
|
|
|
|
const _getAllFilesFromFolder = function(dir, includeSubFolders = true) {
|
|
|
|
const dirPath = path.resolve(__dirname, dir);
|
|
|
|
let results = [];
|
|
|
|
|
2020-01-22 10:49:07 +01:00
|
|
|
filesystem.readdirSync(dirPath).forEach(file => {
|
2019-12-10 19:11:31 +01:00
|
|
|
if (file.charAt(0) === '_') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const filePath = path.join(dirPath, file);
|
|
|
|
const stat = filesystem.statSync(filePath);
|
|
|
|
|
|
|
|
if (stat && stat.isDirectory() && includeSubFolders) {
|
2020-01-22 10:49:07 +01:00
|
|
|
results = results.concat(
|
|
|
|
_getAllFilesFromFolder(filePath, includeSubFolders),
|
|
|
|
);
|
2019-12-10 19:11:31 +01:00
|
|
|
} else {
|
|
|
|
results.push(filePath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
// add page specific scripts
|
|
|
|
const typesJSPath = path.join(theme, 'js/types');
|
|
|
|
if (filesystem.existsSync(typesJSPath)) {
|
|
|
|
const pageScripts = _getAllFilesFromFolder(typesJSPath, true);
|
2020-01-22 10:49:07 +01:00
|
|
|
pageScripts.forEach(file => {
|
2019-12-10 19:11:31 +01:00
|
|
|
includes[`app_${path.basename(file, '.js')}`] = file;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// add page specific scss
|
|
|
|
const typesSCSSPath = path.join(theme, 'scss/types');
|
|
|
|
if (filesystem.existsSync(typesSCSSPath)) {
|
|
|
|
const scssIncludes = _getAllFilesFromFolder(typesSCSSPath, true);
|
2020-01-22 10:49:07 +01:00
|
|
|
scssIncludes.forEach(file => {
|
2019-12-10 19:11:31 +01:00
|
|
|
includes[`app_${path.basename(file, '.scss')}`] = file;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_addAppFiles(SOURCEDIR);
|
|
|
|
|
|
|
|
// remove unnecessary elements for the demo
|
|
|
|
delete includes['app_cms'];
|
|
|
|
delete includes['app_editor'];
|
|
|
|
delete includes['app_order'];
|
|
|
|
|
2019-06-08 17:20:51 +02:00
|
|
|
module.exports = {
|
2019-12-10 19:11:31 +01:00
|
|
|
entry: includes,
|
2019-06-08 17:20:51 +02:00
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'dist'),
|
2019-12-10 19:11:31 +01:00
|
|
|
filename: path.join('js', '[name].js'),
|
|
|
|
publicPath: path.resolve(__dirname, 'dist'),
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
2020-01-22 10:49:07 +01:00
|
|
|
devtool: COMPRESS ? '' : 'source-map',
|
2019-06-08 17:20:51 +02:00
|
|
|
externals: {
|
2020-01-22 10:49:07 +01:00
|
|
|
jquery: 'jQuery',
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
namedModules: true, // NamedModulesPlugin()
|
2020-01-22 10:49:07 +01:00
|
|
|
splitChunks: {
|
|
|
|
// CommonsChunkPlugin()
|
2019-06-08 17:20:51 +02:00
|
|
|
name: 'vendor',
|
2020-01-22 10:49:07 +01:00
|
|
|
minChunks: 2,
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
noEmitOnErrors: true, // NoEmitOnErrorsPlugin
|
|
|
|
concatenateModules: true, //ModuleConcatenationPlugin
|
|
|
|
minimizer: [
|
2019-10-20 03:19:20 +02:00
|
|
|
new TerserPlugin({
|
|
|
|
parallel: true,
|
2019-10-20 04:40:30 +02:00
|
|
|
sourceMap: !COMPRESS,
|
2019-10-20 03:19:20 +02:00
|
|
|
terserOptions: {
|
|
|
|
parse: {
|
|
|
|
ecma: 8,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
ecma: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2020-01-22 10:49:07 +01:00
|
|
|
],
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
module: {
|
2020-01-22 10:49:07 +01:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'es2015',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
['stage-2'],
|
|
|
|
],
|
|
|
|
plugins: [['transform-react-jsx'], ['react-hot-loader/babel']],
|
|
|
|
},
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
},
|
2020-01-22 10:49:07 +01:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: 'ts-loader',
|
|
|
|
exclude: /node_modules/,
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
2020-01-22 10:49:07 +01:00
|
|
|
{
|
|
|
|
test: /\.coffee?$/,
|
|
|
|
use: 'coffee-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
use: {
|
|
|
|
loader: 'worker-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !COMPRESS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !COMPRESS,
|
|
|
|
plugins: [autoprefixer()],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'resolve-url-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !COMPRESS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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)$/,
|
2019-06-08 17:20:51 +02:00
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
2020-01-22 10:49:07 +01:00
|
|
|
outputPath: 'img/',
|
|
|
|
publicPath: '../img/',
|
|
|
|
},
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
2020-01-22 10:49:07 +01:00
|
|
|
],
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: [
|
|
|
|
path.resolve(__dirname, 'src'),
|
|
|
|
path.resolve(__dirname, 'node_modules'),
|
|
|
|
],
|
|
|
|
alias: {
|
2020-01-22 10:49:07 +01:00
|
|
|
jquery: require.resolve('jquery'),
|
|
|
|
jQuery: require.resolve('jquery'),
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-20 04:40:30 +02:00
|
|
|
plugins: plugins,
|
2019-06-08 17:20:51 +02:00
|
|
|
|
|
|
|
devServer: {
|
|
|
|
host: '127.0.0.1',
|
|
|
|
port: 8001,
|
|
|
|
historyApiFallback: true,
|
|
|
|
hot: false,
|
|
|
|
clientLogLevel: 'info',
|
|
|
|
contentBase: [
|
|
|
|
path.resolve(__dirname, 'src'),
|
|
|
|
path.resolve(__dirname, 'node_modules'),
|
|
|
|
path.resolve(__dirname, 'dist'),
|
|
|
|
],
|
|
|
|
//watchContentBase: true,
|
|
|
|
overlay: {
|
|
|
|
warnings: true,
|
2020-01-22 10:49:07 +01:00
|
|
|
errors: true,
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
2020-01-22 10:49:07 +01:00
|
|
|
},
|
2019-06-08 17:20:51 +02:00
|
|
|
},
|
|
|
|
};
|