ToolJet/frontend/webpack.config.js

106 lines
2.3 KiB
JavaScript

var HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const environment = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const API_URL = {
production: process.env.TOOLJET_SERVER_URL || '',
development: 'http://localhost:3000',
};
module.exports = {
mode: environment,
optimization: {
usedExports: true,
},
target: 'web',
resolve: {
extensions: ['.js', '.jsx', '.png'],
alias: {
'@': path.resolve(__dirname, 'src/'),
'@ee': path.resolve(__dirname, 'ee/'),
},
},
devtool: environment === 'development' ? 'inline-source-map' : 'source-map',
module: {
rules: [
{
test: /\.ttf$/,
use: ['file-loader'],
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
limit: 10000,
},
},
],
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /\.scss$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
resolve: {
extensions: ['.js', '.jsx'],
},
use: {
loader: 'babel-loader',
options: {
plugins: [
['import', { libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false }, 'lodash'],
],
},
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /(en)$/),
],
devServer: {
historyApiFallback: true,
},
output: {
publicPath: process.env.ASSET_PATH || '/',
path: path.resolve(__dirname, 'build'),
},
externals: {
// global app config object
config: JSON.stringify({
apiUrl: `${API_URL[environment] || ''}/api`,
SERVER_IP: process.env.SERVER_IP,
COMMENT_FEATURE_ENABLE: true,
}),
},
};