Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce esbuild on webpack #14578

Merged
merged 17 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ steps:
pull: always
image: techknowlogick/xgo:go-1.16.x
commands:
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs bsdtar\|libarchive-tools
- export PATH=$PATH:$GOPATH/bin
- make release
environment:
Expand Down Expand Up @@ -591,7 +591,7 @@ steps:
pull: always
image: techknowlogick/xgo:go-1.16.x
commands:
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs bsdtar\|libarchive-tools
- export PATH=$PATH:$GOPATH/bin
- make release
environment:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ coverage.all
/public/css
/public/fonts
/public/img/webpack
/web_src/fomantic/node_modules
/web_src/fomantic/.npmrc
/web_src/fomantic/semantic.json
/web_src/fomantic/build/*
!/web_src/fomantic/build/semantic.js
!/web_src/fomantic/build/semantic.css
Expand All @@ -93,6 +96,7 @@ coverage.all
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
/VERSION
/.air
/.npm-cache

# Snapcraft
snap/.snapcraft/
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ audit=false
fund=false
package-lock=true
save-exact=true
cache=.npm-cache
50 changes: 39 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(fi

FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
FOMANTIC_DEST := web_src/fomantic/build/semantic.js web_src/fomantic/build/semantic.css
FOMANTIC_DEST_DIR := web_src/fomantic/build
FOMANTIC_WORK_DIR := web_src/fomantic

WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
WEBPACK_CONFIGS := webpack.config.js
Expand Down Expand Up @@ -617,9 +617,9 @@ release-compress: | $(DIST_DIRS)
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;

.PHONY: release-sources
release-sources: | $(DIST_DIRS) node_modules
release-sources: | $(DIST_DIRS) npm-cache
echo $(VERSION) > $(STORED_VERSION_FILE)
tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache --exclude=./$(AIR_TMP_DIR) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
bsdtar --exclude=^./$(DIST) --exclude=^./.git --exclude=^./$(MAKE_EVIDENCE_DIR) --exclude=node_modules --exclude=^./$(AIR_TMP_DIR) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
6543 marked this conversation as resolved.
Show resolved Hide resolved
rm -f $(STORED_VERSION_FILE)

.PHONY: release-docs
Expand All @@ -637,6 +637,26 @@ node_modules: package-lock.json
npm install --no-save
@touch node_modules

.PHONY: npm-cache
npm-cache: .npm-cache $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui

.npm-cache: package-lock.json
rm -rf .npm-cache
$(eval ESBUILD_VERSION := `node -p "require('./package-lock.json').dependencies.esbuild.version"`)
$(eval ESBUILD_PKGS := esbuild-{darwin-64,linux-{arm,arm64,32,64},windows-{32,64}}@$(ESBUILD_VERSION))
npm config --userconfig=.npmrc set cache=.npm-cache
rm -rf node_modules && npm install --no-save
npm config --userconfig=$(FOMANTIC_WORK_DIR)/.npmrc set cache=../../.npm-cache
echo $(ESBUILD_PKGS) fsevents@1 fsevents@2 | tr " " "\n" | xargs -n 1 -P 4 npm cache add
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these fsevents can be dropped, they are generally considered optional dependencies, so nothing should break if they are not there.

Copy link
Member

@silverwind silverwind Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I wonder where they are required in first place. I know some webpack 4 modules did need them as a optional dependency to chokidar but if I run a npm ls fsevents or npm ls chokidar on a Mac on master, I get an empty result. So maybe they are already obsolete?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay those are actually for gulp, which requires chokidar@2 and fsevents@1. fsevents@2 isn't needed by anything as of now. My bad. PR is on the way.

rm -rf $(FOMANTIC_WORK_DIR)/node_modules
@touch .npm-cache

.PHONY: npm-uncache
npm-uncache:
rm -rf .npm-cache
rm -f $(FOMANTIC_WORK_DIR)/.npmrc
npm config --userconfig=.npmrc rm cache

.PHONY: npm-update
npm-update: node-check | node_modules
npx updates -cu
Expand All @@ -647,14 +667,22 @@ npm-update: node-check | node_modules
.PHONY: fomantic
fomantic: $(FOMANTIC_DEST)

$(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) | node_modules
@if [ ! -d node_modules/fomantic-ui ]; then \
npm install --no-save --no-package-lock fomantic-ui@2.8.7; \
fi
rm -rf $(FOMANTIC_DEST_DIR)
cp -f web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
cp -rf web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
npx gulp -f node_modules/fomantic-ui/gulpfile.js build
$(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui:
ln -sf ../../semantic.json $(FOMANTIC_WORK_DIR)
cd $(FOMANTIC_WORK_DIR); \
rm -rf node_modules && mkdir node_modules && \
npm install less@3 fomantic-ui --no-package-lock; \
6543 marked this conversation as resolved.
Show resolved Hide resolved
rm -f semantic.json
@touch $(FOMANTIC_WORK_DIR)/node_modules

$(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui
ln -sf ../../semantic.json $(FOMANTIC_WORK_DIR)
rm -rf $(FOMANTIC_WORK_DIR)/build
cd $(FOMANTIC_WORK_DIR); \
cp -f theme.config.less node_modules/fomantic-ui/src/theme.config; \
cp -rf _site node_modules/fomantic-ui/src/; \
npx gulp -f node_modules/fomantic-ui/gulpfile.js build; \
rm -f semantic.json
@touch $(FOMANTIC_DEST)

.PHONY: webpack
Expand Down
74 changes: 61 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"css-minimizer-webpack-plugin": "1.2.0",
"dropzone": "5.7.2",
"easymde": "2.13.0",
"esbuild-loader": "2.8.0",
"escape-goat": "3.0.0",
"fast-glob": "3.2.4",
"file-loader": "6.2.0",
Expand Down
10 changes: 5 additions & 5 deletions semantic.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"themes": "src/themes/"
},
"output": {
"packaged": "../../web_src/fomantic/build/",
"uncompressed": "../../web_src/fomantic/build/components/",
"compressed": "../../web_src/fomantic/build/components/",
"themes": "../../web_src/fomantic/build/themes/"
"packaged": "../../build/",
"uncompressed": "../../build/components/",
"compressed": "../../build/components/",
"themes": "../../build/themes/"
},
"clean": "../../web_src/fomantic/build/"
"clean": "../../build/"
},
"permission": false,
"autoInstall": false,
Expand Down
45 changes: 7 additions & 38 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const LicenseCheckerWebpackPlugin = require('license-checker-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const {statSync} = require('fs');
const {ESBuildPlugin, ESBuildMinifyPlugin} = require('esbuild-loader');
const {resolve, parse} = require('path');
const {SourceMapDevToolPlugin} = require('webpack');

Expand Down Expand Up @@ -78,13 +77,9 @@ module.exports = {
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
output: {
comments: false,
},
},
new ESBuildMinifyPlugin({
target: 'es2015', // Syntax to compile to (see options below for possible values)
Copy link
Member

@6543 6543 Mar 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target: 'es2015', // Syntax to compile to (see options below for possible values)
target: 'es2015',

(there are no options below to see)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

(This comment was copied from the module README, should not be there)

minify: true
}),
new CssMinimizerPlugin({
sourceMap: true,
Expand Down Expand Up @@ -131,36 +126,9 @@ module.exports = {
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
loader: 'esbuild-loader',
options: {
sourceMaps: true,
cacheDirectory: true,
cacheCompression: false,
cacheIdentifier: [
resolve(__dirname, 'package.json'),
resolve(__dirname, 'package-lock.json'),
resolve(__dirname, 'webpack.config.js'),
].map((path) => statSync(path).mtime.getTime()).join(':'),
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3,
},
],
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
}
],
],
generatorOpts: {
compact: false,
},
target: 'es2015' // Syntax to compile to (see options below for possible values)
6543 marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
Expand Down Expand Up @@ -243,6 +211,7 @@ module.exports = {
},
plugins: [
new VueLoaderPlugin(),
new ESBuildPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[name].css',
Expand Down