0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/webpack.config.js

143 lines
5.0 KiB
JavaScript
Raw Normal View History

/* global require, module, process, __dirname */
2020-03-11 22:32:20 +01:00
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
const webpackDevServerHost = process.env.WEBPACK_HOT_RELOAD_HOST || '127.0.0.1'
2020-03-11 22:37:10 +01:00
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
2020-05-06 11:15:32 +02:00
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'inline-source-map',
2020-03-11 22:54:22 +01:00
entry: {
2020-03-14 15:53:14 +01:00
main: './frontend/src/index.js',
editor: './frontend/src/editor/index.js',
2020-03-11 22:54:22 +01:00
},
watchOptions: {
ignored: /node_modules/,
},
2020-03-11 22:37:10 +01:00
output: {
2020-03-14 15:53:14 +01:00
path: path.resolve(__dirname, 'frontend', 'dist'),
2020-03-11 22:54:22 +01:00
filename: '[name].js',
chunkFilename: '[name].[contenthash].js',
publicPath:
process.env.NODE_ENV === 'production'
? '/static/'
: `http${process.env.LOCAL_HTTPS ? 's' : ''}://${webpackDevServerHost}:8234/static/`,
2020-03-11 22:37:10 +01:00
},
2020-03-18 22:38:42 +01:00
resolve: {
alias: {
'~': path.resolve(__dirname, 'frontend', 'src'),
lib: path.resolve(__dirname, 'frontend', 'src', 'lib'),
scenes: path.resolve(__dirname, 'frontend', 'src', 'scenes'),
...(process.env.NODE_ENV !== 'production'
? {
'react-dom': '@hot-loader/react-dom',
}
: {}),
},
2020-03-18 22:38:42 +01:00
},
2020-03-11 22:37:10 +01:00
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
2020-03-11 22:32:20 +01:00
loader: 'babel-loader',
},
2020-03-11 22:37:10 +01:00
},
{
// Apply rule for .sass, .scss or .css files
test: /\.(sa|sc|c)ss$/,
// Set loaders to transform files.
// Loaders are applying from right to left(!)
// The first loader will be applied after others
use: [
{
// After all CSS loaders we use plugin to do his work.
// It gets all transformed CSS and extracts it into separate
// single bundled file
2020-03-11 22:32:20 +01:00
loader: MiniCssExtractPlugin.loader,
2020-03-11 22:37:10 +01:00
},
{
// This loader resolves url() and @imports inside CSS
2020-03-11 22:32:20 +01:00
loader: 'css-loader',
2020-03-11 22:37:10 +01:00
},
{
// Then we apply postCSS fixes like autoprefixer and minifying
2020-03-11 22:32:20 +01:00
loader: 'postcss-loader',
2020-03-11 22:37:10 +01:00
},
{
// First we transform SASS to standard CSS
2020-03-11 22:32:20 +01:00
loader: 'sass-loader',
2020-03-11 22:37:10 +01:00
options: {
2020-03-11 22:32:20 +01:00
implementation: require('sass'),
},
},
],
2020-03-11 22:37:10 +01:00
},
{
// Now we apply rule for images
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
// Using file-loader for these files
2020-03-11 22:32:20 +01:00
loader: 'file-loader',
2020-03-11 22:37:10 +01:00
// In options we can set different things like format
// and directory to save
options: {
name: '[name].[contenthash].[ext]',
2020-03-11 22:32:20 +01:00
outputPath: 'images',
},
},
],
2020-03-11 22:37:10 +01:00
},
{
// Apply rule for fonts files
test: /\.(woff|woff2|ttf|otf|eot)$/,
use: [
{
// Using file-loader too
2020-03-11 22:32:20 +01:00
loader: 'file-loader',
2020-03-11 22:37:10 +01:00
options: {
name: '[name].[contenthash].[ext]',
2020-03-11 22:32:20 +01:00
outputPath: 'fonts',
},
},
],
},
],
2020-03-11 22:37:10 +01:00
},
devServer: {
contentBase: path.join(__dirname, 'frontend', 'dist'),
hot: true,
host: webpackDevServerHost,
port: 8234,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
},
},
2020-03-11 22:37:10 +01:00
plugins: [
new MiniCssExtractPlugin({
2020-03-11 22:32:20 +01:00
filename: '[name].css',
}),
new HtmlWebpackPlugin({
alwaysWriteToDisk: true,
title: 'PostHog',
chunks: ['main'],
template: path.join(__dirname, 'frontend', 'src', 'index.html'),
}),
new HtmlWebpackPlugin({
alwaysWriteToDisk: true,
title: 'PostHog',
filename: 'layout.html',
chunks: ['main'],
inject: false,
template: path.join(__dirname, 'frontend', 'src', 'layout.ejs'),
}),
new HtmlWebpackHarddiskPlugin(),
2020-03-11 22:32:20 +01:00
],
}