New: Add Github actions lint + build [ARCH-38] (#159)

* New: Add Github actions lint + build [ARCH-38]

* move to right folder

* remove if

* change name

* remove unused code

* fix

* fix lint js

* fix phplint + temp

* change php

* remove temp
This commit is contained in:
ronkelementor 2021-06-10 13:47:01 +03:00 committed by GitHub
parent 1cc44a62eb
commit 36986aa3ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 11977 additions and 117 deletions

21
.editorconfig Normal file
View file

@ -0,0 +1,21 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

47
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,47 @@
name: Build

on: [push, pull_request]


jobs:
build_plugin:
name: Build theme
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci
- name: Bump version on push to release or develop
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/heads/release/') || github.ref == 'refs/heads/develop')
run: |
npm config set git-tag-version false
if [ "${GITHUB_REF:11}" == "develop" ];
then npm version patch
fi
if [[ "${GITHUB_REF:11:7}" == "release" ]];
then npm version minor
fi
- name: Build
run: npm run zip
- name: Upload zip file to GitHub actions artifact
uses: actions/upload-artifact@v2
with:
name: hello-elementor
path: hello-elementor.*.zip
retention-days: 7

65
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,65 @@
name: Lint

on: [push, pull_request]

jobs:
eslint:
name: ESLint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci
- name: Run Lint
run: npm run lint:js

phpcs:
name: PHPCS
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP 7.4
uses: shivammathur/setup-php@9882bed06691b3a085010c1602ce43ef18f15c5b # v2
with:
php-version: '7.4'
- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer packages
run: |
composer install --no-progress
composer require php-parallel-lint/php-parallel-lint
- name: Run Lint
run: |
vendor/bin/phpcs -p -s -n . --standard=./phpcs.xml --extensions=php
- name: Run PHP Syntax Lint
run: |
export PATH=$HOME/.composer/vendor/bin:$PATH
vendor/bin/parallel-lint --blame --exclude node_modules --exclude vendor .

2
.gitignore vendored
View file

@ -2,6 +2,7 @@
node_modules/ node_modules/
.sass-cache/ .sass-cache/
build/ build/
hello-elementor/
log/ log/
vendor/ vendor/
composer.lock composer.lock
@ -14,3 +15,4 @@ Thumbs.db
yarn.lock yarn.lock
assets/js/ assets/js/
*.css *.css
*.zip

View file

@ -12,8 +12,6 @@ module.exports = function( grunt ) {
grunt.initConfig( { grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ), pkg: grunt.file.readJSON( 'package.json' ),


webpack: require( './webpack' ),

sass: { sass: {
options: { options: {
implementation: sass, implementation: sass,
@ -23,7 +21,7 @@ module.exports = function( grunt ) {
expand: true, expand: true,
cwd: 'assets/scss', cwd: 'assets/scss',
src: '*.scss', src: '*.scss',
dest: './', dest: './build',
ext: '.css', ext: '.css',
} ], } ],
}, },
@ -62,8 +60,8 @@ module.exports = function( grunt ) {
files: [ { files: [ {
expand: true, expand: true,
src: [ src: [
'*.css', 'build/*.css',
'!*.min.css', '!build/*.min.css',
], ],
ext: '.min.css', ext: '.min.css',
} ], } ],
@ -135,10 +133,6 @@ module.exports = function( grunt ) {
'wp_readme_to_markdown', 'wp_readme_to_markdown',
] ); ] );


grunt.registerTask( 'watch_scripts', ( isDevMode = false ) => {
grunt.task.run( 'webpack:development' );
} );

grunt.registerTask( 'styles', [ grunt.registerTask( 'styles', [
'sass', 'sass',
'postcss', 'postcss',

View file

@ -178,7 +178,7 @@ export default class ControlsHook extends $e.modules.hookUI.After {
*/ */
toggleLayoutClass( element, classPrefix, inputOptions, inputValue ) { toggleLayoutClass( element, classPrefix, inputOptions, inputValue ) {
// Loop through the possible classes and remove the one that's not in use // Loop through the possible classes and remove the one that's not in use
Object.entries( inputOptions ).forEach( ( [ key, value ] ) => { Object.entries( inputOptions ).forEach( ( [ key ] ) => {
element.removeClass( classPrefix + key ); element.removeClass( classPrefix + key );
} ); } );


@ -210,7 +210,7 @@ export default class ControlsHook extends $e.modules.hookUI.After {
/** /**
* The hook logic. * The hook logic.
*/ */
apply( args, result ) { apply( args ) {
const allThemeControls = this.getHelloThemeControls(), const allThemeControls = this.getHelloThemeControls(),
// Extract the control ID from the passed args // Extract the control ID from the passed args
controlId = Object.keys( args.settings )[ 0 ], controlId = Object.keys( args.settings )[ 0 ],

238
composer.lock generated Normal file
View file

@ -0,0 +1,238 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a622e373d113e65b40d9fc8226a50733",
"packages": [
{
"name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v0.7.1",
"source": {
"type": "git",
"url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
"reference": "fe390591e0241955f22eb9ba327d137e501c771c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c",
"reference": "fe390591e0241955f22eb9ba327d137e501c771c",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=5.3",
"squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0"
},
"require-dev": {
"composer/composer": "*",
"phpcompatibility/php-compatibility": "^9.0",
"sensiolabs/security-checker": "^4.1.0"
},
"type": "composer-plugin",
"extra": {
"class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
},
"autoload": {
"psr-4": {
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Franck Nijhof",
"email": "franck.nijhof@dealerdirect.com",
"homepage": "http://www.frenck.nl",
"role": "Developer / IT Manager"
}
],
"description": "PHP_CodeSniffer Standards Composer Installer Plugin",
"homepage": "http://www.dealerdirect.com",
"keywords": [
"PHPCodeSniffer",
"PHP_CodeSniffer",
"code quality",
"codesniffer",
"composer",
"installer",
"phpcs",
"plugin",
"qa",
"quality",
"standard",
"standards",
"style guide",
"stylecheck",
"tests"
],
"support": {
"issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
"source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
},
"time": "2020-12-07T18:04:37+00:00"
},
{
"name": "elementor/elementor-sniffs",
"version": "v0.2.0",
"source": {
"type": "git",
"url": "https://github.com/elementor/elementor-sniffs.git",
"reference": "065f099cbe1a216e92ec23c573b3739b5f805dcb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/elementor/elementor-sniffs/zipball/065f099cbe1a216e92ec23c573b3739b5f805dcb",
"reference": "065f099cbe1a216e92ec23c573b3739b5f805dcb",
"shasum": ""
},
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"php": ">=5.6",
"wp-coding-standards/wpcs": "^2.3"
},
"type": "phpcodesniffer-standard",
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0+"
],
"authors": [
{
"name": "Elementor Team",
"email": "support@elementor.com"
}
],
"description": "Elementor sniffs",
"keywords": [
"elementor",
"phpcs",
"standards",
"wordpress"
],
"support": {
"source": "https://github.com/elementor/elementor-sniffs/tree/v0.2.0"
},
"time": "2020-12-06T15:03:57+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.6.0",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
"reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"bin": [
"bin/phpcs",
"bin/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
"keywords": [
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2021-04-09T00:54:41+00:00"
},
{
"name": "wp-coding-standards/wpcs",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
"reference": "7da1894633f168fe244afc6de00d141f27517b62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62",
"reference": "7da1894633f168fe244afc6de00d141f27517b62",
"shasum": ""
},
"require": {
"php": ">=5.4",
"squizlabs/php_codesniffer": "^3.3.1"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6",
"phpcompatibility/php-compatibility": "^9.0",
"phpcsstandards/phpcsdevtools": "^1.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"suggest": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically."
},
"type": "phpcodesniffer-standard",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Contributors",
"homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors"
}
],
"description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
"keywords": [
"phpcs",
"standards",
"wordpress"
],
"support": {
"issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues",
"source": "https://github.com/WordPress/WordPress-Coding-Standards",
"wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki"
},
"time": "2020-05-13T23:57:56+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.0.0"
}

View file

@ -89,7 +89,7 @@ class Elementor_Upsell extends \WP_Customize_Control {
echo $customizer_content; echo $customizer_content;
} }


private function get_customizer_upsell_html( $title, $text, $url, $button_text, $image ){ private function get_customizer_upsell_html( $title, $text, $url, $button_text, $image ) {
return sprintf( ' return sprintf( '
<div class="customize-control-header-footer-holder"> <div class="customize-control-header-footer-holder">
<img src="%5$s"> <img src="%5$s">

View file

@ -220,12 +220,12 @@ add_action( 'elementor/experiments/default-features-registered', function( Exper
function hello_header_footer_experiment_active() { function hello_header_footer_experiment_active() {
// If Elementor is not active, return false // If Elementor is not active, return false
if ( ! did_action( 'elementor/loaded' ) ) { if ( ! did_action( 'elementor/loaded' ) ) {
return FALSE; return false;
} }
// Backwards compat. // Backwards compat.
if ( ! method_exists( Plugin::$instance->experiments, 'is_feature_active' ) ) { if ( ! method_exists( Plugin::$instance->experiments, 'is_feature_active' ) ) {
return FALSE; return false;
} }


return ( bool )( Plugin::$instance->experiments->is_feature_active( 'hello-theme-header-footer' ) ); return (bool) ( Plugin::$instance->experiments->is_feature_active( 'hello-theme-header-footer' ) );
} }

View file

@ -142,7 +142,7 @@ class Settings_Footer extends Tab_Base {
], ],
], ],
'condition' => [ 'condition' => [
'hello_footer_width' =>'boxed', 'hello_footer_width' => 'boxed',
], ],
'selectors' => [ 'selectors' => [
'.site-footer .footer-inner' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%;', '.site-footer .footer-inner' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%;',
@ -196,7 +196,7 @@ class Settings_Footer extends Tab_Base {
'tab' => 'hello-settings-footer', 'tab' => 'hello-settings-footer',
'label' => __( 'Site Logo', 'hello-elementor' ), 'label' => __( 'Site Logo', 'hello-elementor' ),
'condition' => [ 'condition' => [
'hello_footer_logo_display!' => '' 'hello_footer_logo_display!' => '',
], ],
] ]
); );

View file

@ -196,7 +196,7 @@ class Settings_Header extends Tab_Base {
'name' => 'hello_header_logo_display', 'name' => 'hello_header_logo_display',
'operator' => '=', 'operator' => '=',
'value' => 'yes', 'value' => 'yes',
] ],
], ],
], ],
] ]
@ -225,7 +225,7 @@ class Settings_Header extends Tab_Base {
'size_units' => [ 'size_units' => [
'%', '%',
'px', 'px',
'vh' 'vh',
], ],
'range' => [ 'range' => [
'px' => [ 'px' => [
@ -303,7 +303,7 @@ class Settings_Header extends Tab_Base {
'name' => 'hello_header_tagline_display', 'name' => 'hello_header_tagline_display',
'operator' => '=', 'operator' => '=',
'value' => 'yes', 'value' => 'yes',
] ],
], ],
], ],
] ]
@ -358,7 +358,7 @@ class Settings_Header extends Tab_Base {
'name' => 'hello_header_menu_display', 'name' => 'hello_header_menu_display',
'operator' => '=', 'operator' => '=',
'value' => 'yes', 'value' => 'yes',
] ],
], ],
], ],
] ]

11434
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,13 @@
"homepage": "https://elementor.com/", "homepage": "https://elementor.com/",
"description": "A sample theme for Elementor.", "description": "A sample theme for Elementor.",
"version": "2.2.1", "version": "2.2.1",
"scripts": {
"build": "grunt default && webpack --env=development && webpack --env=production",
"build:watch": "grunt default watch & webpack --env=developmentWithWatch & webpack --env=productionWithWatch",
"clean:build": "rimraf build && rimraf hello-elementor",
"zip": "npm run clean:build && npm run build && mv build hello-elementor && zip -r hello-elementor.$npm_package_version.zip hello-elementor/*",
"lint:js": "eslint ."
},
"devDependencies": { "devDependencies": {
"@babel/core": "7.0.0", "@babel/core": "7.0.0",
"@babel/plugin-proposal-class-properties": "^7.2.1", "@babel/plugin-proposal-class-properties": "^7.2.1",
@ -12,6 +19,7 @@
"autoprefixer": "~8.5.2", "autoprefixer": "~8.5.2",
"babel-eslint": "^8.2.6", "babel-eslint": "^8.2.6",
"babel-loader": "8.0.0", "babel-loader": "8.0.0",
"copy-webpack-plugin": "^9.0.0",
"cssnano": "~3.10.0", "cssnano": "~3.10.0",
"eslint": "^5.16.0", "eslint": "^5.16.0",
"eslint-config-wordpress": "^2.0.0", "eslint-config-wordpress": "^2.0.0",
@ -21,19 +29,22 @@
"eslint-plugin-no-jquery": "^2.5.0", "eslint-plugin-no-jquery": "^2.5.0",
"eslint-plugin-react": "^7.11.1", "eslint-plugin-react": "^7.11.1",
"eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1", "eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1",
"grunt": "^1.0.4", "grunt": "^1.4.1",
"grunt-checktextdomain": "^1.0.1", "grunt-checktextdomain": "^1.0.1",
"grunt-contrib-sass": "~1.0.0", "grunt-contrib-sass": "~1.0.0",
"grunt-contrib-watch": "~1.1.0", "grunt-contrib-watch": "~1.1.0",
"grunt-postcss": "~0.9.0", "grunt-postcss": "~0.9.0",
"grunt-sass": "~2.1.0", "grunt-sass": "~2.1.0",
"grunt-text-replace": "~0.4.0", "grunt-text-replace": "~0.4.0",
"grunt-webpack": "^4.0.2", "grunt-webpack": "^4.0.3",
"grunt-wp-readme-to-markdown-with-extra": "~2.2.0", "grunt-wp-readme-to-markdown-with-extra": "~2.2.0",
"load-grunt-tasks": "^4.0.0", "load-grunt-tasks": "^4.0.0",
"matchdep": "~2.0.0", "matchdep": "~2.0.0",
"node-sass": "^5.0.0", "node-sass": "^5.0.0",
"webpack": "^5.11.0" "npm-build-zip": "^1.0.3",
"rimraf": "^3.0.2",
"webpack": "^5.11.0",
"webpack-cli": "^4.7.2"
}, },
"dependencies": { "dependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.2.0", "@babel/plugin-transform-modules-commonjs": "^7.2.0",

View file

@ -10,7 +10,8 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
?> ?>
<?php <?php
while ( have_posts() ) : the_post(); while ( have_posts() ) :
the_post();
?> ?>


<main <?php post_class( 'site-main' ); ?> role="main"> <main <?php post_class( 'site-main' ); ?> role="main">

139
webpack.config.js Normal file
View file

@ -0,0 +1,139 @@
/**
* Grunt webpack task config
* @package Elementor
*/
const path = require( 'path' );

const CopyPlugin = require( 'copy-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );

const moduleRules = {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-env' ],
plugins: [
[ '@babel/plugin-proposal-class-properties' ],
[ '@babel/plugin-transform-runtime' ],
[ '@babel/plugin-transform-modules-commonjs' ],
[ '@babel/plugin-proposal-optional-chaining' ],
],
},
},
],
},
],
};

const entry = {
'hello-editor': path.resolve( __dirname, './assets/dev/js/editor/hello-editor.js' ),
'hello-frontend': path.resolve( __dirname, './assets/dev/js/frontend/hello-frontend.js' ),
};

const webpackConfig = {
target: 'web',
context: __dirname,
module: moduleRules,
entry: entry,
mode: 'development',
plugins: [
new CopyPlugin( {
patterns: [
{
from: '**/*',
context: __dirname,
to: path.resolve( __dirname, 'build' ),
// Terser skip this file for minimization
info: { minimized: true },
globOptions: {
ignore: [
'**.zip',
'**.css',
'**/karma.conf.js',
'**/assets/dev/**',
'**/assets/scss/**',
'**/assets/js/qunit-tests*',
'**/bin/**',
'**/build/**',
'**/composer.json',
'**/composer.lock',
'**/Gruntfile.js',
'**/node_modules/**',
'**/npm-debug.log',
'**/package-lock.json',
'**/package.json',
'**/phpcs.xml',
'**/README.md',
'**/readme.txt',
'**/webpack.config.js',
'**/vendor/**',
],
},
},
],
} ),
],
output: {
path: path.resolve( __dirname, './build/assets/js' ),
filename: '[name].js',
devtoolModuleFilenameTemplate: './[resource]',
},
};

const webpackProductionConfig = {
target: 'web',
context: __dirname,
module: moduleRules,
entry: {
...entry,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin( {
terserOptions: {
keep_fnames: true,
},
include: /\.min\.js$/,
} ),
],
},
mode: 'production',
output: {
path: path.resolve( __dirname, './build/assets/js' ),
filename: '[name].js',
},
performance: { hints: false },
};

// Add minified entry points
Object.entries( webpackProductionConfig.entry ).forEach( ( [ wpEntry, value ] ) => {
webpackProductionConfig.entry[ wpEntry + '.min' ] = value;

delete webpackProductionConfig.entry[ wpEntry ];
} );

module.exports = ( env ) => {
if ( env.developmentWithWatch ) {
return { ...webpackConfig, watch: true, devtool: 'source-map' };
}

if ( env.productionWithWatch ) {
return { ...webpackProductionConfig, watch: true, devtool: 'source-map' };
}

if ( env.production ) {
return webpackProductionConfig;
}

if ( env.development ) {
return webpackConfig;
}

throw new Error( 'missing or invalid --env= development/production/developmentWithWatch/productionWithWatch' );
};

View file

@ -1,92 +0,0 @@
/**
* Grunt webpack task config
* @package Elementor
*/
const path = require( 'path' );

const TerserPlugin = require( 'terser-webpack-plugin' );

const moduleRules = {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-env' ],
plugins: [
[ '@babel/plugin-proposal-class-properties' ],
[ '@babel/plugin-transform-runtime' ],
[ '@babel/plugin-transform-modules-commonjs' ],
[ '@babel/plugin-proposal-optional-chaining' ],
],
},
},
],
},
],
};

const entry = {
'hello-editor': path.resolve( __dirname, './assets/dev/js/editor/hello-editor.js' ),
'hello-frontend': path.resolve( __dirname, './assets/dev/js/frontend/hello-frontend.js' ),
};

const webpackConfig = {
target: 'web',
context: __dirname,
devtool: 'source-map',
module: moduleRules,
entry: entry,
mode: 'development',
output: {
path: path.resolve( __dirname, './assets/js' ),
filename: '[name].js',
devtoolModuleFilenameTemplate: './[resource]',
},
watch: true,
};

const webpackProductionConfig = {
target: 'web',
context: __dirname,
devtool: 'source-map',
module: moduleRules,
entry: {
...entry,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin( {
terserOptions: {
keep_fnames: true,
},
include: /\.min\.js$/
} ),
],
},
mode: 'production',
output: {
path: path.resolve( __dirname, './assets/js' ),
filename: '[name].js',
},
performance: { hints: false },
};

// Add minified entry points
Object.entries( webpackProductionConfig.entry ).forEach( ( [ entry, value ] ) => {
webpackProductionConfig.entry[ entry + '.min' ] = value;

delete webpackProductionConfig.entry[ entry ];
} );


const gruntWebpackConfig = {
development: webpackConfig,
production: webpackProductionConfig
};

module.exports = gruntWebpackConfig;