Skip to content

Instantly share code, notes, and snippets.

@zacck-zz
Created August 16, 2019 16:43
Show Gist options
  • Save zacck-zz/416446ac25d97a44cd7557d27847d029 to your computer and use it in GitHub Desktop.
Save zacck-zz/416446ac25d97a44cd7557d27847d029 to your computer and use it in GitHub Desktop.
'use strict'
const autoprefixer = require('autoprefixer')
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
const getClientEnvironment = require('./env')
const paths = require('../config/paths')
const publicPath = '/'
const publicUrl = ''
const env = getClientEnvironment(publicUrl)
module.exports = {
mode: 'development',
devtool: 'cheap-module-source-map',
entry: [
require.resolve('./polyfills'),
require.resolve('../scripts/utils/webpackHotDevClient'),
require.resolve('react-error-overlay'),
paths.appIndexJs
],
output: {
pathinfo: true,
filename: 'static/js/bundle.js',
chunkFilename: 'static/js/[name].chunk.js',
publicPath: publicPath,
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
},
optimization: {
splitChunks: {
chunks: 'all',
name: 'vendors'
},
runtimeChunk: true
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.elm']
},
module: {
noParse: /\.elm$/,
strictExportPresence: true,
rules: [
// Disable require.ensure as it's not a standard language feature.
{ parser: { requireEnsure: false } },
{
test: /\.js$/,
exclude: [/[/\\\\]elm-stuff[/\\\\]/, /[/\\\\]node_modules[/\\\\]/],
include: paths.appSrc,
loader: require.resolve('babel-loader'),
query: {
presets: [
[
require.resolve('@babel/preset-env'),
{
useBuiltIns: 'entry',
modules: false
}
]
],
plugins: [
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true
}
]
]
}
},
{
test: /\.js$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
babelrc: false,
compact: false,
presets: [
[
// Latest stable ECMAScript features
require('@babel/preset-env').default,
{
// Do not transform modules to CJS
modules: false
}
]
],
cacheDirectory: true,
highlightCode: true
}
}
]
},
{
test: /\.elm$/,
include: paths.appSrc,
exclude: [/[/\\\\]elm-stuff[/\\\\]/, /[/\\\\]node_modules[/\\\\]/],
use: [
{
loader: require.resolve('elm-hot-webpack-loader')
},
{
loader: require.resolve('string-replace-loader'),
query: {
search: '%PUBLIC_URL%',
replace: publicUrl,
flags: 'g'
}
},
{
loader: require.resolve('elm-webpack-loader'),
options: {
verbose: true,
// If ELM_DEBUGGER was set to "false", disable it. Otherwise
// for invalid values, "true" and as a default, enable it
debug: process.env.ELM_DEBUGGER !== 'false',
pathToElm: paths.elm,
forceWatch: true
}
}
]
},
{
test: /\.css/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1
}
},
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss',
plugins: () => [
require('tailwindcss'),
require('postcss-flexbugs-fixes'),
autoprefixer({
flexbox: 'no-2009'
})
]
}
}
]
},
{
exclude: [/\.html$/, /\.js$/, /\.elm$/, /\.css$/, /\.scss$/, /\.sass$/, /\.json$/, /\.svg$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
},
// "file" loader for svg
{
test: /\.svg$/,
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
},
plugins: [
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml
}),
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
new webpack.DefinePlugin(env.stringified),
new webpack.HotModuleReplacementPlugin(),
new CaseSensitivePathsPlugin()
],
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
performance: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment