diff --git a/.babelrc b/.babelrc index 69f50d59a72b..0339d5d0ee6a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { "presets": ["env"] -} \ No newline at end of file +} diff --git a/.eslintrc.json b/.eslintrc.json index 72133f8c5369..384c0813a0a1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,6 @@ "node": true, "es6": true }, - "extends": "eslint:recommended", "parserOptions": { "ecmaVersion": 6, "sourceType": "module", diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 1c8e82b659f3..f6c9ba73aa05 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -25,4 +25,4 @@ build: command: './vendor/bin/phpcs --standard=PMAStandard ./ --report=checkstyle --report-file=cs-data --ignore=*/vendor/*,*/build/*' analysis: file: 'cs-data' # The reporter filename - format: 'php-cs-checkstyle' # The supported format by Scrutinizer \ No newline at end of file + format: 'php-cs-checkstyle' # The supported format by Scrutinizer diff --git a/doc/config.rst b/doc/config.rst index cc07e4f1a17f..d80f41bbc4dc 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -3409,13 +3409,21 @@ Developer Enable you to set the working environment for loading js files +.. config:option:: $cfg['webpack_host'] + + :type: string + :default: `'http://localhost'` + + Enable you to start webpack development server on specified host for serving js files + when working in the development environment + .. config:option:: $cfg['webpack_port'] - :type: integer + :type: number :default: 3307 - Enable you to start webpack development server for serving js files - when woking in the development environment + Enable you to start webpack development server on specified port for serving js files + when working in the development environment .. config:option:: $cfg['DBG'] diff --git a/js/ajax.js b/js/ajax.js index 6ef58e278769..fe07967bdbf5 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -646,9 +646,10 @@ var AJAX = { */ var check = name.split('_'); if (check[check.length - 1] === 'new.js') { - var script_src = ''; + var script_src; if (PMA_commonParams.get('environment') === 'development') { - script_src += 'http://localhost:' + PMA_commonParams.get('webpack_port') + '/js/dist/'; + script_src = PMA_commonParams.get('webpack_host') + ':' + + PMA_commonParams.get('webpack_port') + '/js/dist/'; } else if (PMA_commonParams.get('environment') === 'production') { script_src = 'js/dist/'; } diff --git a/libraries/classes/Header.php b/libraries/classes/Header.php index 760178ff6e96..c252a0f5cbbd 100644 --- a/libraries/classes/Header.php +++ b/libraries/classes/Header.php @@ -236,6 +236,7 @@ public function getJsParams(): array $params = [ 'environment' => $GLOBALS['cfg']['environment'], + 'webpack_host' => $GLOBALS['cfg']['webpack_host'], 'webpack_port' => $GLOBALS['cfg']['webpack_port'], 'common_query' => Url::getCommonRaw(), 'opendb_url' => Util::getScriptNameForOption( diff --git a/libraries/classes/Scripts.php b/libraries/classes/Scripts.php index 8889a776a734..52b93fef8f04 100644 --- a/libraries/classes/Scripts.php +++ b/libraries/classes/Scripts.php @@ -59,10 +59,9 @@ private function _includeFiles(array $files) * DOM so that both new and old files can be used simultaneously * It checks whether the file contains new in its name or not */ + $src = ""; if ($GLOBALS['cfg']['environment'] === 'development') { - $src = "http://localhost:" . $GLOBALS['cfg']['webpack_port'] . "/"; - } else if ($GLOBALS['cfg']['environment'] === 'production'){ - $src = ""; + $src = $GLOBALS['cfg']['webpack_host'] . ":" . $GLOBALS['cfg']['webpack_port'] . "/"; } $result .= '' . "\n"; diff --git a/libraries/config.default.php b/libraries/config.default.php index 9b06e07a162c..f3979ebb8aac 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -110,6 +110,23 @@ */ $cfg['blowfish_secret'] = ''; +/** + * Working environment configuration + * for development mode $cfg['environment'] = 'development', + * for making production build $cfg['environment'] = 'production' + * + */ +$cfg['environment'] = 'production'; + +/** + * Webppack host for running development server of webpack + */ +$cfg['webpack_host'] = 'http://localhost'; + +/** + * Webppack port number for running development server of webpack + */ +$cfg['webpack_port'] = 3307; /******************************************************************************* * Server(s) configuration @@ -3014,8 +3031,12 @@ /** * Additional string to allow in CSP headers. + * + * For working envionment to be development, this has to be changed to allow + * cross-origin loading of js files for specified webpack host and webpack port. + * Eg. 'http://localhost:3307 ws://localhost:3307' for locahost and 3307 webpack pot */ - $cfg['CSPAllow'] = ''; +$cfg['CSPAllow'] = ''; /** * Disable the table maintenance mass operations, like optimizing or diff --git a/package.json b/package.json index fe18ef992696..010063afc013 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "license": "GPL-2.0", "scripts": { "dev:wds": "webpack-dev-server --progress", - "prod:build": "rimraf lib dist && babel js/es6/ -d lib --ignore .test.js && cross-env NODE_ENV=production webpack -p --progress" + "prod:build": "del js/lib js/dist && babel js/src/ -d js/lib --ignore .test.js && cross-env NODE_ENV=production webpack -p --progress", + "lint:check": "eslint js/src/*.js", + "lint:fix": "eslint js/src/*.js --fix" }, "dependencies": { "codemirror": "5.37.0", @@ -24,12 +26,12 @@ "zxcvbn": "4.4.2" }, "devDependencies": { - "babel-core": "^6.26.3", + "babel-cli": "6.26.0", "babel-loader": "^7.1.4", "babel-preset-env": "^1.7.0", "cross-env": "^5.1.5", + "del-cli": "^1.1.0", "eslint": "^4.9.0", - "rimraf": "^2.6.2", "webpack": "^4.8.3", "webpack-cli": "^2.1.3", "webpack-dev-server": "^3.1.4" diff --git a/webpack.config.babel.js b/webpack.config.babel.js index c24d9a7ff9f7..f06702cd28bb 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -31,9 +31,9 @@ export default [{ db_search_new: './js/src/db_search.js' }, output: { - filename: 'js/sql.js', + filename: 'db_search_new.js', path: path.resolve(__dirname, 'dist'), - publicPath: 'http://localhost:3007/dist' + publicPath: 'http://localhost:3307/js/dist' }, module: module, // devtool: 'source-map',