2018-02-10 20:58:29 +00:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
2018-03-08 00:09:08 +00:00
|
|
|
const WebappPlugin = require('webapp-webpack-plugin');
|
2018-02-10 20:58:29 +00:00
|
|
|
const HtmlPlugin = require('html-webpack-plugin');
|
|
|
|
|
|
|
|
const pkg = require('./package.json');
|
2018-02-13 22:28:47 +00:00
|
|
|
const buildId = [
|
|
|
|
process.env.CIRCLE_BRANCH || 'prerelease',
|
|
|
|
process.env.CIRCLE_BUILD_NUM || '##',
|
|
|
|
(process.env.CIRCLE_SHA1 || 'gitsha').slice(0, 7)
|
|
|
|
].join('-');
|
2018-02-10 20:58:29 +00:00
|
|
|
|
|
|
|
const pages = fs.readdirSync(path.resolve(__dirname, 'src/pages'));
|
|
|
|
const pagePlugins = pages.map(name => new HtmlPlugin({
|
2018-02-13 22:28:47 +00:00
|
|
|
description: pkg.description,
|
|
|
|
buildId,
|
2018-02-13 22:10:32 +00:00
|
|
|
template: './src/template.html',
|
2018-02-11 12:42:52 +00:00
|
|
|
filename: `${ name }.html`,
|
2018-02-10 20:58:29 +00:00
|
|
|
chunks: ['common', name],
|
|
|
|
minify: {
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
keepClosingSlash: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
minifyURLs: true
|
2018-02-13 22:28:47 +00:00
|
|
|
},
|
|
|
|
...require(`./src/pages/${ name }/config`)
|
2018-02-10 20:58:29 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: pages.reduce((pages, name) => {
|
2018-02-13 22:10:32 +00:00
|
|
|
pages[name] = `./src/pages/${ name }/browser`;
|
2018-02-10 20:58:29 +00:00
|
|
|
return pages;
|
|
|
|
}, {}),
|
|
|
|
output: {
|
|
|
|
filename: 'js/[name].[chunkhash:8].js',
|
|
|
|
chunkFilename: 'js/[name].[chunkhash:8].js',
|
|
|
|
path: path.resolve(__dirname, 'build')
|
|
|
|
},
|
2018-02-14 01:09:52 +00:00
|
|
|
resolve: {
|
|
|
|
modules: ['src', 'node_modules']
|
|
|
|
},
|
2018-03-08 00:09:08 +00:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
2018-03-30 21:06:33 +00:00
|
|
|
chunks: 'initial',
|
2018-03-08 00:09:08 +00:00
|
|
|
name: 'common',
|
2018-05-28 16:03:49 +00:00
|
|
|
minChunks: 2
|
2018-03-08 00:09:08 +00:00
|
|
|
}
|
|
|
|
},
|
2018-02-10 20:58:29 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.EnvironmentPlugin({
|
2018-02-11 14:12:48 +00:00
|
|
|
NODE_ENV: 'development',
|
2018-02-15 22:55:37 +00:00
|
|
|
DEPLOY_ENV: 'development',
|
2018-02-11 14:12:48 +00:00
|
|
|
GA_PROPERTY: null,
|
|
|
|
SENTRY_KEY: null,
|
2018-02-11 15:41:03 +00:00
|
|
|
BANNER: process.env.NODE_ENV === 'production' ? null : (process.env.NODE_ENV || 'development'),
|
2018-02-13 22:28:47 +00:00
|
|
|
BUILD_ID: buildId
|
2018-02-10 20:58:29 +00:00
|
|
|
}),
|
2018-03-08 00:09:08 +00:00
|
|
|
new ExtractTextPlugin({
|
2018-03-30 00:47:19 +00:00
|
|
|
filename: 'css/[name].[chunkhash:8].css',
|
2018-03-08 00:09:08 +00:00
|
|
|
allChunks: true
|
2018-02-10 20:58:29 +00:00
|
|
|
}),
|
2018-03-08 00:09:08 +00:00
|
|
|
new CopyPlugin(['./public']),
|
|
|
|
...pagePlugins,
|
|
|
|
new WebappPlugin({ // MUST be after pagePlugins
|
2018-02-10 20:58:29 +00:00
|
|
|
logo: './src/favicon.svg',
|
2018-03-08 00:09:08 +00:00
|
|
|
prefix: 'icons-[hash:8]/',
|
2018-02-10 20:58:29 +00:00
|
|
|
inject: true,
|
2018-03-08 00:09:08 +00:00
|
|
|
favicons: {
|
2018-02-10 20:58:29 +00:00
|
|
|
appName: 'Regexper',
|
|
|
|
appDescription: pkg.description,
|
2018-03-08 00:09:08 +00:00
|
|
|
developerURL: 'https://github.com/javallone/',
|
2018-02-10 20:58:29 +00:00
|
|
|
background: '#6b6659',
|
|
|
|
theme_color: '#bada55',
|
|
|
|
start_url: '/',
|
|
|
|
icons: {
|
|
|
|
android: true,
|
|
|
|
appleIcon: true,
|
|
|
|
coast: false,
|
|
|
|
favicons: true,
|
|
|
|
firefox: false,
|
|
|
|
windows: true,
|
|
|
|
yandex: false
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 00:09:08 +00:00
|
|
|
})
|
2018-02-10 20:58:29 +00:00
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
2018-02-13 22:45:27 +00:00
|
|
|
{
|
|
|
|
test: /locales/,
|
|
|
|
loader: '@alienfast/i18next-loader',
|
|
|
|
options: {
|
|
|
|
basenameAsNamespace: true
|
|
|
|
}
|
|
|
|
},
|
2018-02-10 21:22:59 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'babel-loader'
|
|
|
|
},
|
2018-02-10 20:58:29 +00:00
|
|
|
{
|
2018-02-13 23:15:18 +00:00
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
minimize: true,
|
|
|
|
sourceMap: true,
|
|
|
|
modules: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2018-02-10 21:32:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
2018-02-11 11:58:59 +00:00
|
|
|
loader: 'svg-react-loader'
|
2018-02-10 20:58:29 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|