Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garybernhardt/2f9dc11d5548943b8ac118341aa8bac9 to your computer and use it in GitHub Desktop.
Save garybernhardt/2f9dc11d5548943b8ac118341aa8bac9 to your computer and use it in GitHub Desktop.
const webpack = require('webpack');
const path = require('path');
const StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const production = process.env.RACK_ENV == 'production'
const config = {
mode: production ? "production" : "development",
entry: './build/client/app.js',
devtool: "source-map",
output: {
path: path.resolve(__dirname, 'public/dist'),
filename: 'bundle.[contenthash].js',
library: 'App'
},
module: {
// Rules are applied bottom-to-top
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
// babel/preset-env may inject import statements in to files when
// polyfilling, and when Webpack sees those import statements, it
// will incorrectly see the file as an ES module, breaking what would
// otherwise be a fine CommonJS file. This line fixes that.
// Details here:
// https://babeljs.io/docs/en/options#sourcetype
sourceType: "unambiguous",
presets: [['@babel/preset-env', {
// Browserslist configuration is in package.json
modules: false,
useBuiltIns: 'usage',
corejs: 2,
}]]
},
},
},
]
},
resolve: {
extensions: [
'.tsx',
'.ts',
'.js',
'.jsx'
]
},
node: {
/* We ignore some Node modules that are imported by TypeScript. */
fs: 'empty',
module: 'empty',
},
plugins: [
new StatsWriterPlugin(),
...(process.env.ANALYZE ? [new BundleAnalyzerPlugin()] : []),
],
stats: "minimal",
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment