chore: webpack config

This commit is contained in:
Mo Bitar
2021-10-23 09:06:59 -05:00
parent 9b06e00ba8
commit 82fc103a3e
6 changed files with 25 additions and 19 deletions

View File

@@ -11,7 +11,7 @@
"parserOptions": { "parserOptions": {
"project": "./app/assets/javascripts/tsconfig.json" "project": "./app/assets/javascripts/tsconfig.json"
}, },
"ignorePatterns": [".eslintrc.js", "webpack.*.js"], "ignorePatterns": [".eslintrc.js", "webpack.*.js", "webpack-defaults.js"],
"rules": { "rules": {
"standard/no-callback-literal": 0, // Disable this as we have too many callbacks relying on literals "standard/no-callback-literal": 0, // Disable this as we have too many callbacks relying on literals
"no-throw-literal": 0, "no-throw-literal": 0,

View File

@@ -10,10 +10,10 @@
"setup": "yarn install", "setup": "yarn install",
"start": "webpack-dev-server --config webpack.dev.js", "start": "webpack-dev-server --config webpack.dev.js",
"watch": "webpack -w --config webpack.dev.js", "watch": "webpack -w --config webpack.dev.js",
"watch:desktop": "webpack -w --config webpack.dev.js --env.platform='desktop'", "watch:desktop": "webpack -w --config webpack.dev.js --env platform='desktop'",
"bundle": "webpack --config webpack.prod.js && yarn tsc", "bundle": "webpack --config webpack.prod.js && yarn tsc",
"bundle:desktop": "webpack --config webpack.prod.js --env.platform='desktop'", "bundle:desktop": "webpack --config webpack.prod.js --env platform='desktop'",
"bundle:desktop:beta": "webpack --config webpack.prod.js --env.platform='desktop' --env.public_beta='true'", "bundle:desktop:beta": "webpack --config webpack.prod.js --env platform='desktop' --env public_beta='true'",
"build": "bundle install && yarn install --frozen-lockfile && bundle exec rails assets:precompile && yarn bundle", "build": "bundle install && yarn install --frozen-lockfile && bundle exec rails assets:precompile && yarn bundle",
"lint": "eslint --fix app/assets/javascripts", "lint": "eslint --fix app/assets/javascripts",
"tsc": "tsc --project app/assets/javascripts/tsconfig.json" "tsc": "tsc --project app/assets/javascripts/tsconfig.json"

13
webpack-defaults.js Normal file
View File

@@ -0,0 +1,13 @@
const Defaults = {
platform: 'web',
};
function mergeWithEnvDefaults(env) {
for (const key of Object.keys(Defaults)) {
if (!env[key]) {
env[key] = Defaults[key];
}
}
}
module.exports = mergeWithEnvDefaults;

View File

@@ -1,14 +1,11 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const mergeWithEnvDefaults = require('./webpack-defaults');
require('dotenv').config(); require('dotenv').config();
const WebEnv = {
platform: 'web',
};
module.exports = (env) => { module.exports = (env) => {
env = Object.assign(env, WebEnv); mergeWithEnvDefaults(env);
return { return {
entry: './app/assets/javascripts/index.ts', entry: './app/assets/javascripts/index.ts',
output: { output: {

View File

@@ -1,14 +1,12 @@
const { merge } = require('webpack-merge'); const { merge } = require('webpack-merge');
const config = require('./webpack.config.js'); const config = require('./webpack.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const mergeWithEnvDefaults = require('./webpack-defaults.js');
const WebEnv = {
platform: 'web',
};
module.exports = (env, argv) => { module.exports = (env, argv) => {
const port = argv.port || 3001; const port = argv.port || 3001;
return merge(config(Object.assign(env, WebEnv), argv), { mergeWithEnvDefaults(env);
return merge(config(env, argv), {
mode: 'development', mode: 'development',
optimization: { optimization: {
minimize: false, minimize: false,

View File

@@ -1,12 +1,10 @@
const { merge } = require('webpack-merge'); const { merge } = require('webpack-merge');
const mergeWithEnvDefaults = require('./webpack-defaults.js');
const config = require('./webpack.config.js'); const config = require('./webpack.config.js');
const WebEnv = {
platform: 'web',
};
module.exports = (env, argv) => { module.exports = (env, argv) => {
return merge(config(Object.assign(env, WebEnv), argv), { mergeWithEnvDefaults(env);
return merge(config(env, argv), {
mode: 'production', mode: 'production',
devtool: 'source-map', devtool: 'source-map',
}); });