Skip to content

Commit

Permalink
Switch from CommonJS to ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymal committed Jun 15, 2024
1 parent 06df17f commit 75e0c8e
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 113 deletions.
2 changes: 1 addition & 1 deletion frontend/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sourceMaps": true,
"sourceType": "unambiguous",
"sourceType": "module",
"presets": [
[
"@babel/preset-env",
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "mini_fiction",
"version": "1.0.0",
"description": "Frontend components",
"type": "module",
"scripts": {
"webpack": "webpack --progress",
"webpack:watch": "webpack --progress --watch",
Expand Down Expand Up @@ -30,7 +31,6 @@
"@babel/eslint-parser": "^7.24.7",
"@babel/plugin-transform-react-jsx": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/register": "^7.24.6",
"@csstools/postcss-global-data": "^2.1.1",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* devblock:start */
import 'preact/debug';
/* devblock:end */

import Baz from 'bazooka';

import core from './legacy/core';
Expand All @@ -19,10 +23,6 @@ import {
transition,
} from './legacy/lib/bootstrap.min';

/* devblock:start */
require('preact/debug');
/* devblock:end */

core.oninit(common.init.bind(common));
core.onload(common.load.bind(common));
core.onunload(common.unload.bind(common));
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/legacy/bell.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import core from './core';
import { post, get } from '../utils/ajax';

'use strict';

var bell = {
_storageEventBind: null,
_updaterInterval: null,
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/legacy/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import common from './common';
import { post, get } from '../utils/ajax';
import { notify, notifyError } from '../utils/notifications';


'use strict';

/* global amajaxify: false, core: false, captcha: false, common: false */


Expand Down
2 changes: 0 additions & 2 deletions frontend/src/legacy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import HTMLSanitizer from './lib/htmlsanitizer';
import { post } from '../utils/ajax';
import { notify, notifyError } from '../utils/notifications';

'use strict';

/* global core: false, $: false, mySettings: false, HTMLSanitizer: false */


Expand Down
3 changes: 0 additions & 3 deletions frontend/src/legacy/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import amajaxify from './lib/amajaxify';
import { get, setCsrfToken } from '../utils/ajax';
import { notifyError } from '../utils/notifications';

'use strict';


var core = {
csrftoken: null,
nav: null,
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/legacy/editlog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/* global core: false */


Expand Down
3 changes: 0 additions & 3 deletions frontend/src/legacy/lib/amajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* немного экономит трафик, гибче и поддерживает модальные окна.
*/


'use strict';

/**
* Собственно главный и единственный модуль.
*
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/legacy/lib/htmlsanitizer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* Создаёт чистилку HTML-кода.
*
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/legacy/story.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import Hypher from 'hypher';
import ruHyphenation from 'hyphenation.ru';

Expand Down
23 changes: 14 additions & 9 deletions frontend/webpack.config.babel.js → frontend/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import { fileURLToPath } from 'url';
import zlib from 'zlib';
import AssetsManifestPlugin from 'webpack-assets-manifest';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
Expand All @@ -15,12 +16,13 @@ import postCSSNano from 'cssnano';
import postCSSCustomProperties from 'postcss-custom-properties';
import postCSSMoveProps from 'postcss-move-props-to-bg-image-query';

const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

const ENV = process.env.NODE_ENV || 'development';
const isDev = ENV !== 'production';

const outputPath = path.resolve(__dirname, '..', 'mini_fiction', 'static', 'build');
const frontendRoot = path.dirname(fileURLToPath(import.meta.url));
const outputPath = path.resolve(frontendRoot, '..', 'mini_fiction', 'static', 'build');
const outputName = `[name].${isDev ? 'dev' : '[contenthash]'}`;

const reactAliases = {
Expand All @@ -36,7 +38,7 @@ const postCSSOptions = {
postCSSMoveProps({
computeCustomProps: root => postcss([
postCSSGlobalData({
files: [path.resolve(__dirname, 'src', 'css', 'variables.css')],
files: [path.resolve(frontendRoot, 'src', 'css', 'variables.css')],
}),
postCSSCustomProperties({preserve: false}),
]).process(root),
Expand Down Expand Up @@ -99,9 +101,9 @@ const productionPlugins = [
}),
];

module.exports = {
export default {
mode: ENV,
context: path.resolve(__dirname, 'src'),
context: path.resolve(frontendRoot, 'src'),
entry: {
index: ['./index.js', './index.css'],
},
Expand All @@ -113,10 +115,10 @@ module.exports = {
},

resolve: {
extensions: ['.jsx', '.js', '.json', 'png', '.jpg', '.gif', '.svg', '.eot', '.ttf', '.woff', '.woff2'],
extensions: ['.jsx', '.js', '.json', '.png', '.jpg', '.gif', '.svg', '.eot', '.ttf', '.woff', '.woff2'],
modules: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules'),
path.resolve(frontendRoot, 'src'),
path.resolve(frontendRoot, 'node_modules'),
'node_modules',
],
alias: reactAliases,
Expand All @@ -126,13 +128,16 @@ module.exports = {
rules: [
{
test: /\.jsx?$/,
exclude: path.resolve(__dirname, 'src'),
exclude: path.resolve(frontendRoot, 'src'),
enforce: 'pre',
use: 'source-map-loader',
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
resolve: {
fullySpecified: false,
},
use: [
{ loader: 'babel-loader' },
{
Expand Down
81 changes: 2 additions & 79 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -939,17 +939,6 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"

"@babel/register@^7.24.6":
version "7.24.6"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.24.6.tgz#59e21dcc79e1d04eed5377633b0f88029a6bef9e"
integrity sha512-WSuFCc2wCqMeXkz/i3yfAAsxwWflEgbVkZzivgAmXl/MxrXeoYFZOOPllbC8R8WTF7u61wSRQtDVZ1879cdu6w==
dependencies:
clone-deep "^4.0.1"
find-cache-dir "^2.0.0"
make-dir "^2.1.0"
pirates "^4.0.6"
source-map-support "^0.5.16"

"@babel/regjsgen@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310"
Expand Down Expand Up @@ -1926,11 +1915,6 @@ common-path-prefix@^3.0.0:
resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0"
integrity sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==

component-emitter@^1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.1.tgz#ef1d5796f7d93f135ee6fb684340b26403c97d17"
Expand Down Expand Up @@ -2869,15 +2853,6 @@ filter-obj@^1.1.0:
resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-1.1.0.tgz#9b311112bc6c6127a16e016c6c5d7f19e0805c5b"
integrity sha512-8rXg1ZnX7xzy2NGDVkBVaAy+lSlPNwad13BtgSlLuxfIslyt5Vg64U7tFcCt4WS1R0hvtnQybT/IyCkGZ3DpXQ==

find-cache-dir@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7"
integrity sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==
dependencies:
commondir "^1.0.1"
make-dir "^2.0.0"
pkg-dir "^3.0.0"

find-cache-dir@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-4.0.0.tgz#a30ee0448f81a3990708f6453633c733e2f6eec2"
Expand All @@ -2886,13 +2861,6 @@ find-cache-dir@^4.0.0:
common-path-prefix "^3.0.0"
pkg-dir "^7.0.0"

find-up@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==
dependencies:
locate-path "^3.0.0"

find-up@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19"
Expand Down Expand Up @@ -3752,14 +3720,6 @@ loader-utils@^2.0.0:
emojis-list "^3.0.0"
json5 "^2.1.2"

locate-path@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==
dependencies:
p-locate "^3.0.0"
path-exists "^3.0.0"

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
Expand Down Expand Up @@ -3842,14 +3802,6 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

make-dir@^2.0.0, make-dir@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
integrity sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==
dependencies:
pify "^4.0.1"
semver "^5.6.0"

map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
Expand Down Expand Up @@ -4163,7 +4115,7 @@ optionator@^0.9.3:
type-check "^0.4.0"
word-wrap "^1.2.5"

p-limit@^2.0.0, p-limit@^2.2.0:
p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
Expand All @@ -4184,13 +4136,6 @@ p-limit@^4.0.0:
dependencies:
yocto-queue "^1.0.0"

p-locate@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4"
integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==
dependencies:
p-limit "^2.0.0"

p-locate@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07"
Expand Down Expand Up @@ -4244,11 +4189,6 @@ pascalcase@^0.1.1:
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
integrity sha512-XHXfu/yOQRy9vYOtUDVMN60OEJjW013GoObG1o+xwQTpB9eYJX/BjXMsdW13ZDPruFhYYn0AG22w0xgQMwl3Nw==

path-exists@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
integrity sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==

path-exists@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
Expand Down Expand Up @@ -4316,18 +4256,6 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==

pirates@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.6.tgz#3018ae32ecfcff6c29ba2267cbf21166ac1f36b9"
integrity sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==

pkg-dir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"
integrity sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==
dependencies:
find-up "^3.0.0"

pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
Expand Down Expand Up @@ -5076,11 +5004,6 @@ section-iterator@^2.0.0:
resolved "https://registry.yarnpkg.com/section-iterator/-/section-iterator-2.0.0.tgz#bf444d7afeeb94ad43c39ad2fb26151627ccba2a"
integrity sha512-xvTNwcbeDayXotnV32zLb3duQsP+4XosHpb/F+tu6VzEZFmIjzPdNk6/O+QOOx5XTh08KL2ufdXeCO33p380pQ==

semver@^5.6.0:
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

semver@^6.3.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
Expand Down Expand Up @@ -5237,7 +5160,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@^0.5.16, source-map-support@~0.5.20:
source-map-support@~0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
Expand Down

0 comments on commit 75e0c8e

Please sign in to comment.