0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/webpack.config.js
Marius Andra 11ff3787e3
PostHog Toolbar (#896)
* can zoom out toolbar

* refactor the look

* add kea localstorage plugin

* add test to see if user is logged in or not

* keep width when resizing window

* increase padding on larger screens

* floating box style

* toolbar close button

* show what's on the current page

* fix close and remove tags

* inspect element

* inspect element improvements

* show stats

* inspect element

* give jsURL to the editor in debug mode

* toolbar HMR

* move styles to CSS

* tabs on toolbar

* css for current page block

* links to dashboards and actions

* adjust the location of the X so that we don't always have a horizontal scrollbar

* clean up some css, incl renaming toolbar divs

* refactor webpack config to use a separate config for the editor chunk, in it include all CSS inside the JS

* load styles behind the shadow, render only once all CSS is loaded

* tolerable design for the floating view

* header block for float + css zindex fix

* fix height

* move toolbar to toolbar folder

* add back old toolbar folder

* load by default editor.js, move new toolbar to toolbar.js

* only open toolbar.js by default, not editor.js

* add comment for toolbar setting

* Updated Yarn lockfile

* fix test and rename is_authenticated -> isAuthenticated in json

* get mypy to play along

* refactor tab content into folders

* refactor code structure for toolbar

* simplify floating/docked/float/dock -> float/dock

* small refactor

* upgrade to posthog-js 1.1.0

* fix array copy code
2020-06-04 13:45:24 +02:00

176 lines
7.1 KiB
JavaScript

/* global require, module, process, __dirname */
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'
// main = app
// toolbar = new toolbar
// editor = old toolbar
module.exports = () => [createEntry('main'), createEntry('toolbar'), createEntry('editor')]
function createEntry(entry) {
return {
name: entry,
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'inline-source-map',
entry: {
[entry]:
entry === 'main'
? './frontend/src/index.js'
: entry === 'toolbar'
? './frontend/src/toolbar/index.js'
: entry === 'editor'
? './frontend/src/editor/index.js'
: null,
},
watchOptions: {
ignored: /node_modules/,
},
output: {
path: path.resolve(__dirname, 'frontend', 'dist'),
filename: '[name].js',
chunkFilename: '[name].[contenthash].js',
publicPath:
process.env.NODE_ENV === 'production' ? '/static/' : `http${process.env.LOCAL_HTTPS ? 's' : ''}://${webpackDevServerHost}:8234/static/`,
},
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',
}
: {}),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
},
},
{
// 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: [
entry === 'main'
? {
// After all CSS loaders we use plugin to do his work.
// It gets all transformed CSS and extracts it into separate
// single bundled file
loader: MiniCssExtractPlugin.loader,
}
: entry === 'toolbar'
? {
loader: 'style-loader',
options: {
insert: function insertAtTop(element) {
// tunnel behind the shadow root
if (window.__PHGTLB_ADD_STYLES__) {
window.__PHGTLB_ADD_STYLES__(element)
} else {
if (!window.__PHGTLB_STYLES__) {
window.__PHGTLB_STYLES__ = []
}
window.__PHGTLB_STYLES__.push(element)
}
},
},
}
: null,
{
// This loader resolves url() and @imports inside CSS
loader: 'css-loader',
},
{
// Then we apply postCSS fixes like autoprefixer and minifying
loader: 'postcss-loader',
},
{
// First we transform SASS to standard CSS
loader: 'sass-loader',
options: {
implementation: require('sass'),
},
},
].filter(a => a),
},
{
// Now we apply rule for images
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
// Using file-loader for these files
loader: 'file-loader',
// In options we can set different things like format
// and directory to save
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'images',
},
},
],
},
{
// Apply rule for fonts files
test: /\.(woff|woff2|ttf|otf|eot)$/,
use: [
{
// Using file-loader too
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'fonts',
},
},
],
},
],
},
devServer: {
contentBase: path.join(__dirname, 'frontend', 'dist'),
hot: true,
host: webpackDevServerHost,
port: 8234,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
},
},
plugins:
entry === 'main'
? [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new HtmlWebpackPlugin({
alwaysWriteToDisk: true,
title: 'PostHog',
template: path.join(__dirname, 'frontend', 'src', 'index.html'),
}),
new HtmlWebpackPlugin({
alwaysWriteToDisk: true,
title: 'PostHog',
filename: 'layout.html',
inject: false,
template: path.join(__dirname, 'frontend', 'src', 'layout.ejs'),
}),
new HtmlWebpackHarddiskPlugin(),
]
: [],
}
}