regexper-static/webpack.common.js

138 lines
3.4 KiB
JavaScript
Raw Normal View History

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');
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');
const buildId = [
2018-06-05 11:09:06 +00:00
process.env.CI_COMMIT_REF_SLUG || 'prerelease',
(process.env.CI_COMMIT_SHA || '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({
description: pkg.description,
buildId,
template: './src/template.html',
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
},
...require(`./src/pages/${ name }/config`)
2018-02-10 20:58:29 +00:00
}));
module.exports = {
entry: pages.reduce((pages, name) => {
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']
},
optimization: {
splitChunks: {
2018-03-30 21:06:33 +00:00
chunks: 'initial',
name: 'common',
2018-05-28 16:03:49 +00:00
minChunks: 2
}
},
2018-02-10 20:58:29 +00:00
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
DEPLOY_ENV: 'development',
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'),
BUILD_ID: buildId
2018-02-10 20:58:29 +00:00
}),
new ExtractTextPlugin({
2018-03-30 00:47:19 +00:00
filename: 'css/[name].[chunkhash:8].css',
allChunks: true
2018-02-10 20:58:29 +00:00
}),
new CopyPlugin(['./public']),
...pagePlugins,
new WebappPlugin({ // MUST be after pagePlugins
2018-02-10 20:58:29 +00:00
logo: './src/favicon.svg',
prefix: 'icons-[hash:8]/',
2018-02-10 20:58:29 +00:00
inject: true,
favicons: {
2018-02-10 20:58:29 +00:00
appName: 'Regexper',
appDescription: pkg.description,
2018-06-05 01:23:27 +00:00
developerURL: 'https://gitlab.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-02-10 20:58:29 +00:00
],
module: {
rules: [
{
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$/,
loader: 'svg-react-loader'
2018-02-10 20:58:29 +00:00
}
]
}
};