regexper-static/webpack.common.js

157 lines
4.0 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 FaviconsPlugin = require('favicons-webpack-plugin-cesco');
const HtmlPlugin = require('html-webpack-plugin');
const pkg = require('./package.json');
const pages = fs.readdirSync(path.resolve(__dirname, 'src/pages'));
const pagePlugins = pages.map(name => new HtmlPlugin({
template: `./src/pages/${ name }/template.js`,
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
}
}));
module.exports = {
entry: pages.reduce((pages, name) => {
pages[name] = `./src/pages/${ name }`;
return pages;
}, {}),
output: {
filename: 'js/[name].[chunkhash:8].js',
chunkFilename: 'js/[name].[chunkhash:8].js',
path: path.resolve(__dirname, 'build')
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_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: [
process.env.CIRCLE_BRANCH || 'prerelease',
process.env.CIRCLE_BUILD_NUM || '##',
2018-02-11 17:18:29 +00:00
(process.env.CIRCLE_SHA1 || 'gitsha').slice(0, 7)
2018-02-11 15:41:03 +00:00
].join('-')
2018-02-10 20:58:29 +00:00
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: 2
}),
new FaviconsPlugin({
logo: './src/favicon.svg',
persistentCache: true,
inject: true,
config: {
appName: 'Regexper',
appDescription: pkg.description,
developerName: pkg.author.name,
developerUrl: 'https://github.com/javallone/',
background: '#6b6659',
theme_color: '#bada55',
start_url: '/',
icons: {
android: true,
appleIcon: true,
coast: false,
favicons: true,
firefox: false,
windows: true,
yandex: false
}
}
}),
new ExtractTextPlugin('css/[name].[contenthash:8].css'),
new CopyPlugin(['./public']),
...pagePlugins
],
module: {
rules: [
2018-02-10 21:22:59 +00:00
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
2018-02-10 20:58:29 +00:00
{
oneOf: [
{
test: /\.css$/,
exclude: /components/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: true,
sourceMap: true,
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss'
}
}
]
})
},
{
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-11 23:37:07 +00:00
},
{
test: /\.yaml$/,
use: [
{
loader: 'json-loader'
},
{
loader: 'yaml-loader'
}
]
2018-02-10 20:58:29 +00:00
}
]
}
};