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

feat: esbuild loader integration #10

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voltranjs",
"version": "1.0.4",
"version": "1.0.5",
"main": "src/index.js",
"author": "Hepsiburada Technology Team",
"bin": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"autoprefixer": "9.3.1",
"axios": "0.19.0",
"babel-eslint": "10.0.1",
"babel-loader": "8.0.6",
"@babel/eslint-parser": "^7.12.1",
"classnames": "2.2.6",
"clean-webpack-plugin": "1.0.0",
"cli-color": "^2.0.0",
Expand All @@ -47,6 +47,7 @@
"css-loader": "1.0.1",
"eev": "0.1.5",
"eslint": "6.1.0",
"esbuild-loader": "^2.11.0",
"eslint-config-airbnb": "18.0.1",
"eslint-config-prettier": "6.3.0",
"eslint-plugin-import": "^2.19.1",
Expand Down Expand Up @@ -92,7 +93,7 @@
"svg-url-loader": "2.3.2",
"terser-webpack-plugin": "2.3.5",
"url-loader": "1.0.1",
"webpack": "4.25.1",
"webpack": "4.46.0",
"webpack-bundle-analyzer": "3.6.0",
"webpack-cli": "3.1.0",
"webpack-dev-middleware": "3.4.0",
Expand Down
78 changes: 37 additions & 41 deletions webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { ESBuildMinifyPlugin } = require('esbuild-loader');

require('intersection-observer');

const {createComponentName} = require('./src/universal/utils/helper.js');
const { createComponentName } = require('./src/universal/utils/helper.js');

const packageJson = require('./package.json');

Expand All @@ -27,11 +28,11 @@ const appConfig = require(appConfigFilePath);
const commonConfig = require('./webpack.common.config');
const postCssConfig = require('./postcss.config');
const babelConfig = require('./babel.server.config');

const voltranClientConfigPath = voltranConfig.webpackConfiguration.client;
const voltranClientConfig = voltranClientConfigPath ?
require(voltranConfig.webpackConfiguration.client) :
'';
const voltranClientConfig = voltranClientConfigPath
? require(voltranConfig.webpackConfiguration.client)
: '';

const normalizeUrl = require('./lib/os.js');
const replaceString = require('./config/string.js');
Expand Down Expand Up @@ -115,35 +116,32 @@ const clientConfig = webpackMerge(commonConfig, voltranClientConfig, {
rules: [
{
test: reScript,
loader: 'esbuild-loader',
include: [path.resolve(__dirname, 'src'), voltranConfig.inputFolder],
loader: 'babel-loader',
options: {
cacheDirectory: isDebug,
babelrc: false,
...babelConfig()
loader: 'jsx',
target: 'es2015'
}
},
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
multiple: [
...replaceString()
]
multiple: [...replaceString()]
}
},
{
test: /\.css$/,
use: [
isDebug
? {
loader: 'style-loader',
options: {
insertAt: 'top',
singleton: true,
sourceMap: false
loader: 'style-loader',
options: {
insertAt: 'top',
singleton: true,
sourceMap: false
}
}
}
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
Expand All @@ -165,13 +163,13 @@ const clientConfig = webpackMerge(commonConfig, voltranClientConfig, {
use: [
isDebug
? {
loader: 'style-loader',
options: {
insertAt: 'top',
singleton: true,
sourceMap: false
loader: 'style-loader',
options: {
insertAt: 'top',
singleton: true,
sourceMap: false
}
}
}
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
Expand Down Expand Up @@ -199,6 +197,10 @@ const clientConfig = webpackMerge(commonConfig, voltranClientConfig, {

optimization: {
minimizer: [
new ESBuildMinifyPlugin({
target: 'es2015',
css: true
}),
new TerserWebpackPlugin({
sourceMap: isDebug,
parallel: true,
Expand All @@ -212,10 +214,10 @@ const clientConfig = webpackMerge(commonConfig, voltranClientConfig, {
...(isBuildingForCDN
? []
: [
new CleanWebpackPlugin([distFolderPath], {
verbose: true
})
]),
new CleanWebpackPlugin([distFolderPath], {
verbose: true
})
]),

new webpack.DefinePlugin({
'process.env.BROWSER': true,
Expand All @@ -233,25 +235,19 @@ const clientConfig = webpackMerge(commonConfig, voltranClientConfig, {
...(isDebug
? [new webpack.HotModuleReplacementPlugin()]
: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id]-[contenthash].css'
})
]),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id]-[contenthash].css'
})
]),

new AssetsPlugin({
path: voltranConfig.inputFolder,
filename: 'assets.json',
prettyPrint: true
}),

...(
isAnalyze ?
[
new BundleAnalyzerPlugin()
] :
[]
),
...(isAnalyze ? [new BundleAnalyzerPlugin()] : [])
]
});

Expand Down
25 changes: 8 additions & 17 deletions webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,23 @@ const nodeExternals = require('webpack-node-externals');
const env = process.env.VOLTRAN_ENV || 'local';

const voltranConfig = require('./voltran.config');

const appConfigFilePath = `${voltranConfig.appConfigFile.entry}/${env}.conf.js`;
const appConfig = require(appConfigFilePath);
const appConfig = require(appConfigFilePath); // eslint-disable-line import/no-dynamic-require

const commonConfig = require('./webpack.common.config');
const babelConfig = require('./babel.server.config');
const postCssConfig = require('./postcss.config');
const normalizeUrl = require('./lib/os.js');
const replaceString = require('./config/string.js');

const voltranServerConfigPath = voltranConfig.webpackConfiguration.server;
const voltranServerConfig = voltranServerConfigPath ?
require(voltranConfig.webpackConfiguration.server) :
'';

const isDebug = voltranConfig.dev;

let styles = '';

for(var i = 0; i < voltranConfig.styles.length; i++) {
for (let i = 0; i < voltranConfig.styles.length; i++) {
styles += `require('${voltranConfig.styles[i]}');`;
}

const serverConfig = webpackMerge(commonConfig,voltranServerConfig, {
const serverConfig = webpackMerge(commonConfig, voltranConfig.webpackConfiguration.server, {
name: 'server',

target: 'node',
Expand All @@ -49,21 +43,18 @@ const serverConfig = webpackMerge(commonConfig,voltranServerConfig, {
rules: [
{
test: /\.(js|jsx|mjs)$/,
loader: 'babel-loader',
loader: 'esbuild-loader',
include: [path.resolve(__dirname, 'src'), voltranConfig.inputFolder],
options: {
cacheDirectory: true,
babelrc: false,
...babelConfig()
loader: 'jsx',
target: 'es2015'
}
},
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
multiple: [
...replaceString()
]
multiple: [...replaceString()]
}
},
{
Expand Down