Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs')
- const path = require('path')
- const ManifestPlugin = require('webpack-manifest-plugin')
- const ExtractTextPlugin = require('extract-text-webpack-plugin')
- const webpack = require('webpack')
- const CopyWebpackPlugin = require('copy-webpack-plugin')
- const ModernizrWebpackPlugin = require('modernizr-webpack-plugin')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const Dotenv = require('dotenv-webpack')
- const APP_DIR = path.resolve(__dirname, '..', 'src')
- const BUILD_DIR = path.resolve(__dirname, '..', 'dist')
- const PROD_ENV = process.env.NODE_ENV === 'production'
- const ENV_FILE = process.env.ENV_FILE
- const envFilePath = (ENV_FILE) ? `./.env.${ENV_FILE}` : './.env'
- require('dotenv').config({
- path: envFilePath
- })
- const extractStyles = new ExtractTextPlugin({
- filename: 'styles.[md5:contenthash:hex:8].css',
- ignoreOrder: true,
- allChunks: true,
- })
- module.exports = {
- entry: [
- '@babel/polyfill',
- `${APP_DIR}/index.tsx`
- ],
- devtool: 'source-map',
- mode: 'production',
- output: {
- path: BUILD_DIR,
- filename: '[name].[hash].js'
- },
- module: {
- rules: [
- {
- test: /\.(jpe?g|png|gif|svg)$/i,
- use: [
- 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]'
- ]
- },
- {
- test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- use: 'url-loader?limit=10000&mimetype=application/font-woff'
- },
- {
- test: /\.(ttf|eot|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- use: 'file-loader'
- },
- {
- test: /\.hbs$/,
- loader : 'handlebars-loader',
- options: {
- knownHelpersOnly: false,
- inlineRequires: '/images/',
- },
- },
- {
- test: /\.tsx?$/,
- use: 'ts-loader',
- exclude: /node_modules/
- },
- {
- test: /src\/(.*)\.s?css$/,
- use: extractStyles.extract({
- fallback: 'style-loader?sourceMap',
- use: [
- {
- loader: 'css-loader',
- options: {
- localIdentName: '[hash:base64:6]',
- modules: true,
- importLoaders: 1,
- minimize: {
- discardComments: {
- removeAll: true
- }
- },
- sourceMap: true
- }
- },
- 'postcss-loader?sourceMap',
- 'resolve-url-loader?sourceMap',
- 'sass-loader?sourceMap'
- ]
- })
- },
- {
- test: /node_modules\/(.*)\.s?css$/,
- exclude: /src\/(.*)\.scss$/,
- use: extractStyles.extract({
- fallback: 'style-loader?sourceMap',
- use: [
- {
- loader: 'css-loader',
- options: {
- minimize: {
- discardComments: {
- removeAll: true
- }
- },
- sourceMap: true
- }
- },
- 'postcss-loader?sourceMap',
- 'resolve-url-loader?sourceMap',
- 'sass-loader?sourceMap'
- ]
- })
- }
- ]
- },
- resolve: {
- extensions: ['.ts', '.tsx', '.js', '.json'],
- },
- plugins: [
- new Dotenv({
- systemvars: true,
- path: envFilePath
- }),
- new webpack.NoEmitOnErrorsPlugin(),
- new HtmlWebpackPlugin({
- filename: 'index.html',
- template: `${APP_DIR}/index.hbs`,
- production: PROD_ENV
- }),
- new CopyWebpackPlugin([{
- from: './src/public'
- }]),
- new ModernizrWebpackPlugin({
- options: [
- 'setClasses'
- ],
- filename: 'modernizr[hash]',
- noChunk: true,
- htmlWebpackPlugin: true
- }),
- extractStyles,
- ],
- optimization: {
- splitChunks: {
- name: 'vendor',
- chunks: 'all'
- }
- }
- }
Add Comment
Please, Sign In to add comment