2020-06-02 11:39:53 +02:00
|
|
|
/* global require, module, process, __dirname */
|
2020-03-11 22:32:20 +01:00
|
|
|
const path = require('path')
|
2023-07-19 12:48:34 +02:00
|
|
|
const webpack = require('webpack')
|
2020-06-02 11:39:53 +02:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin')
|
2023-06-12 08:53:54 +02:00
|
|
|
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
|
2020-06-02 11:39:53 +02:00
|
|
|
|
|
|
|
const webpackDevServerHost = process.env.WEBPACK_HOT_RELOAD_HOST || '127.0.0.1'
|
2020-11-11 19:14:07 +01:00
|
|
|
const webpackDevServerFrontendAddr = webpackDevServerHost === '0.0.0.0' ? '127.0.0.1' : webpackDevServerHost
|
2020-06-04 13:45:24 +02:00
|
|
|
|
|
|
|
function createEntry(entry) {
|
2020-11-16 11:40:08 +01:00
|
|
|
const commonLoadersForSassAndLess = [
|
2021-05-31 23:58:28 +02:00
|
|
|
{
|
|
|
|
loader: 'style-loader',
|
|
|
|
},
|
2020-11-16 11:40:08 +01:00
|
|
|
{
|
|
|
|
// This loader resolves url() and @imports inside CSS
|
|
|
|
loader: 'css-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Then we apply postCSS fixes like autoprefixer and minifying
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-06-04 13:45:24 +02:00
|
|
|
return {
|
|
|
|
name: entry,
|
|
|
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
2021-06-29 22:20:02 +02:00
|
|
|
devtool:
|
|
|
|
process.env.GENERATE_SOURCEMAP === 'false'
|
|
|
|
? false
|
|
|
|
: process.env.NODE_ENV === 'production'
|
|
|
|
? 'source-map'
|
|
|
|
: 'inline-source-map',
|
2020-06-04 13:45:24 +02:00
|
|
|
entry: {
|
2022-05-27 14:31:17 +02:00
|
|
|
[entry]: entry === 'main' || entry === 'cypress' ? './frontend/src/index.tsx' : null,
|
2020-04-14 21:41:26 +02:00
|
|
|
},
|
2020-06-04 13:45:24 +02:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'frontend', 'dist'),
|
|
|
|
chunkFilename: '[name].[contenthash].js',
|
2021-05-20 12:10:27 +02:00
|
|
|
publicPath: process.env.JS_URL
|
|
|
|
? `${process.env.JS_URL}${process.env.JS_URL.endsWith('/') ? '' : '/'}static/`
|
|
|
|
: process.env.NODE_ENV === 'production'
|
|
|
|
? '/static/'
|
|
|
|
: `http${process.env.LOCAL_HTTPS ? 's' : ''}://${webpackDevServerFrontendAddr}:8234/static/`,
|
2020-06-04 13:45:24 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
2021-11-03 09:50:24 +01:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
2020-06-04 13:45:24 +02:00
|
|
|
alias: {
|
|
|
|
'~': path.resolve(__dirname, 'frontend', 'src'),
|
|
|
|
lib: path.resolve(__dirname, 'frontend', 'src', 'lib'),
|
|
|
|
scenes: path.resolve(__dirname, 'frontend', 'src', 'scenes'),
|
2022-06-10 17:03:06 +02:00
|
|
|
'@posthog/apps-common': path.resolve(__dirname, 'frontend', '@posthog', 'apps-common', 'src'),
|
|
|
|
'@posthog/lemon-ui': path.resolve(__dirname, 'frontend', '@posthog', 'lemon-ui', 'src'),
|
2023-11-23 17:40:46 +01:00
|
|
|
'@posthog/ee/exports': [
|
|
|
|
path.resolve(__dirname, 'ee', 'frontend', 'exports'),
|
|
|
|
path.resolve(__dirname, 'frontend', '@posthog', 'ee', 'exports'),
|
|
|
|
],
|
2022-03-15 17:36:51 +01:00
|
|
|
storybook: path.resolve(__dirname, '.storybook'),
|
2020-08-14 17:02:57 +02:00
|
|
|
types: path.resolve(__dirname, 'frontend', 'types'),
|
2020-10-26 12:49:50 +01:00
|
|
|
public: path.resolve(__dirname, 'frontend', 'public'),
|
2021-02-09 16:28:01 +01:00
|
|
|
cypress: path.resolve(__dirname, 'cypress'),
|
2023-07-19 12:48:34 +02:00
|
|
|
process: 'process/browser',
|
2020-03-11 22:37:10 +01:00
|
|
|
},
|
2020-06-04 13:45:24 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2020-07-08 09:45:23 +02:00
|
|
|
test: /\.[jt]sx?$/,
|
2023-05-11 17:40:13 +02:00
|
|
|
exclude: /(node_modules)/,
|
2020-06-04 13:45:24 +02:00
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
2020-03-11 22:37:10 +01:00
|
|
|
},
|
2020-06-04 13:45:24 +02: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: [
|
2020-11-16 11:40:08 +01:00
|
|
|
...commonLoadersForSassAndLess,
|
2020-06-04 13:45:24 +02:00
|
|
|
{
|
|
|
|
// First we transform SASS to standard CSS
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
implementation: require('sass'),
|
|
|
|
},
|
|
|
|
},
|
2020-07-03 14:37:07 +02:00
|
|
|
].filter((a) => a),
|
2020-06-04 13:45:24 +02:00
|
|
|
},
|
2020-11-05 13:55:33 +01:00
|
|
|
{
|
|
|
|
// Apply rule for less files (used to import and override AntD)
|
|
|
|
test: /\.(less)$/,
|
|
|
|
use: [
|
2020-11-16 11:40:08 +01:00
|
|
|
...commonLoadersForSassAndLess,
|
2020-11-05 13:55:33 +01:00
|
|
|
{
|
|
|
|
loader: 'less-loader', // compiles Less to CSS
|
|
|
|
options: {
|
|
|
|
lessOptions: {
|
|
|
|
javascriptEnabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2020-06-04 13:45:24 +02:00
|
|
|
{
|
|
|
|
// Now we apply rule for images
|
2022-06-06 12:50:13 +02:00
|
|
|
test: /\.(png|jpe?g|gif|svg|lottie)$/,
|
2020-06-04 13:45:24 +02:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
// Using file-loader for these files
|
|
|
|
loader: 'file-loader',
|
2020-03-11 22:37:10 +01:00
|
|
|
|
2020-06-04 13:45:24 +02:00
|
|
|
// In options we can set different things like format
|
|
|
|
// and directory to save
|
|
|
|
options: {
|
|
|
|
name: '[name].[contenthash].[ext]',
|
|
|
|
outputPath: 'images',
|
|
|
|
},
|
2020-03-11 22:32:20 +01:00
|
|
|
},
|
2020-06-04 13:45:24 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// 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',
|
|
|
|
},
|
2020-03-11 22:32:20 +01:00
|
|
|
},
|
2020-06-04 13:45:24 +02:00
|
|
|
],
|
|
|
|
},
|
2020-10-13 15:44:56 +02:00
|
|
|
{
|
|
|
|
// Apply rule for sound files
|
|
|
|
test: /\.(mp3)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
// Using file-loader too
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[contenthash].[ext]',
|
|
|
|
outputPath: 'sounds',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-06-12 08:53:54 +02:00
|
|
|
// probably only need this because we're using webpack v4
|
|
|
|
{
|
|
|
|
test: /monaco-editor\/.*\.m?js/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
2020-06-04 13:45:24 +02:00
|
|
|
],
|
|
|
|
},
|
2021-03-12 14:54:29 +01:00
|
|
|
// add devServer config only to 'main' entry
|
|
|
|
...(entry === 'main'
|
|
|
|
? {
|
|
|
|
devServer: {
|
|
|
|
contentBase: path.join(__dirname, 'frontend', 'dist'),
|
|
|
|
hot: true,
|
|
|
|
host: webpackDevServerHost,
|
|
|
|
port: 8234,
|
|
|
|
stats: 'minimal',
|
|
|
|
disableHostCheck: !!process.env.LOCAL_HTTPS,
|
|
|
|
public: process.env.JS_URL
|
|
|
|
? new URL(process.env.JS_URL).host
|
|
|
|
: `${webpackDevServerFrontendAddr}:8234`,
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
'Access-Control-Allow-Headers': '*',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {}),
|
2020-07-10 13:31:35 +02:00
|
|
|
plugins: [
|
2023-06-12 08:53:54 +02:00
|
|
|
new MonacoWebpackPlugin(),
|
2020-07-10 13:31:35 +02:00
|
|
|
// common plugins for all entrypoints
|
|
|
|
].concat(
|
2020-06-04 13:45:24 +02:00
|
|
|
entry === 'main'
|
|
|
|
? [
|
2020-07-10 13:31:35 +02:00
|
|
|
// we need these only once per build
|
2020-06-04 13:45:24 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
alwaysWriteToDisk: true,
|
|
|
|
title: 'PostHog',
|
|
|
|
template: path.join(__dirname, 'frontend', 'src', 'index.html'),
|
|
|
|
}),
|
2020-07-23 10:41:59 +02:00
|
|
|
|
2020-06-04 13:45:24 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
alwaysWriteToDisk: true,
|
|
|
|
title: 'PostHog',
|
|
|
|
filename: 'layout.html',
|
|
|
|
inject: false,
|
|
|
|
template: path.join(__dirname, 'frontend', 'src', 'layout.ejs'),
|
|
|
|
}),
|
|
|
|
new HtmlWebpackHarddiskPlugin(),
|
|
|
|
]
|
2021-02-09 16:28:01 +01:00
|
|
|
: entry === 'cypress'
|
2023-07-19 12:48:34 +02:00
|
|
|
? [
|
|
|
|
new HtmlWebpackHarddiskPlugin(),
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser',
|
|
|
|
}),
|
|
|
|
]
|
2020-07-10 13:31:35 +02:00
|
|
|
: []
|
|
|
|
),
|
2020-06-04 13:45:24 +02:00
|
|
|
}
|
2020-03-11 22:32:20 +01:00
|
|
|
}
|
2021-02-09 16:28:01 +01:00
|
|
|
|
|
|
|
// main = app
|
2022-05-27 14:31:17 +02:00
|
|
|
module.exports = () => [createEntry('main')]
|
2021-02-09 16:28:01 +01:00
|
|
|
module.exports.createEntry = createEntry
|