Skip to content

Instantly share code, notes, and snippets.

@Kikobeats
Last active February 22, 2017 19:55
Show Gist options
  • Save Kikobeats/1840434e20374d5fade6a3b49e040a8a to your computer and use it in GitHub Desktop.
Save Kikobeats/1840434e20374d5fade6a3b49e040a8a to your computer and use it in GitHub Desktop.
autotrack + webpack
'use strict'
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
const PurifyCSSWebpackPlugin = require('purifycss-webpack-plugin')
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const PreloadWebpackPlugin = require('preload-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const OfflinePlugin = require('offline-plugin')
const webpack = require('webpack')
const path = require('path')
const config = require('./config.json')
const pkg = require('./package.json')
const { HashedModuleIdsPlugin } = webpack
const {
OccurrenceOrderPlugin,
AggressiveMergingPlugin,
CommonsChunkPlugin,
UglifyJsPlugin } = webpack.optimize
module.exports = {
devtool: 'source-map',
entry: [
'./src/app/index.js'
],
output: {
path: path.resolve('src/www'),
filename: 'assets/js/bundle.js'
},
resolve: {
extensions: ['.scss', '.css', '.js'],
modules: ['node_modules']
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules\/(?!(autotrack|dom-utils))/,
use: ['babel-loader'],
include: path.resolve('src/app')
}, {
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader?minimize&sourceMap',
'sass-loader',
'postcss-loader'
]
})
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
'APP_VERSION': JSON.stringify(pkg.version)
}),
new HashedModuleIdsPlugin(),
new OccurrenceOrderPlugin(),
new AggressiveMergingPlugin(),
new ExtractTextPlugin({
allChunks: true,
filename: 'assets/css/bundle.css'
}),
new PurifyCSSWebpackPlugin({
basePath: path.resolve('src/www'),
resolveExtensions: ['.js'],
purifyOptions: {
minify: true,
rejected: true
}
}),
new CommonsChunkPlugin({
name: 'vendor',
filename: 'assets/js/vendor.bundle.js',
minChunks: Infinity
}),
new UglifyJsPlugin({
sourceMap: true,
minimize: true,
compress: { warnings: false },
comments: false
}),
new OfflinePlugin({
relativePaths: false,
publicPath: '/',
caches: {
main: [':rest:'],
additional: [
'assets/js/vendor.bundle.js',
':externals:'
],
externals: [
'https://static.hotjar.com/c/hotjar-342795.js?sv=5',
'https://www.google-analytics.com/analytics.js'
]
},
safeToUseOptionalCaches: true,
AppCache: false
}),
new HtmlWebpackPlugin(Object.assign({}, config, {
template: path.resolve('index.ejs'),
alwaysWriteToDisk: true,
inject: false,
hash: true,
minify: {
collapseWhitespace: true,
decodeEntities: true,
html5: true,
processConditionalComments: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeTagWhitespace: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
})),
new PreloadWebpackPlugin(),
new HtmlWebpackHarddiskPlugin(),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: true,
logLevel: 'error'
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment