From f7a7e341a570e0156ac6152797c2cccb581f0323 Mon Sep 17 00:00:00 2001 From: rork Date: Wed, 11 Apr 2018 18:14:35 +0400 Subject: [PATCH 01/10] add checking on this.options object and utils.getOptions function existence for webpack 4 --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 416414c..8d6c5d4 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,9 @@ module.exports = function (source) { this.cacheable && this.cacheable(); var query = typeof this.query === 'object' ? this.query : utils.parseQuery(this.query); - var opts = merge(this.options['ejs-compiled-loader'] || {}, query); + var _options = typeof this.options === 'object' ? this.options['ejs-compiled-loader'] || {} : {}; + _options = typeof utils.getOptions === 'function' ? merge(utils.getOptions(this), _options) : _options; + var opts = merge(_options, query); opts.client = true; // Skip compile debug for production when running with From c4a9395980ef6b05f8c881ef3aa93c21d89a5aa5 Mon Sep 17 00:00:00 2001 From: rork Date: Fri, 13 Apr 2018 16:27:02 +0400 Subject: [PATCH 02/10] some improves, works with webpack-html-plugin and like loader with extract loader --- index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8d6c5d4..70c49d8 100644 --- a/index.js +++ b/index.js @@ -6,14 +6,16 @@ var ejs = require('ejs'), merge = require('merge'); -module.exports = function (source) { +module.exports = function(source) { this.cacheable && this.cacheable(); - var query = typeof this.query === 'object' ? this.query : utils.parseQuery(this.query); var _options = typeof this.options === 'object' ? this.options['ejs-compiled-loader'] || {} : {}; _options = typeof utils.getOptions === 'function' ? merge(utils.getOptions(this), _options) : _options; var opts = merge(_options, query); - opts.client = true; + + if (opts.client == undefined) { + opts.client = true; + } // Skip compile debug for production when running with // webpack --optimize-minimize @@ -31,11 +33,14 @@ module.exports = function (source) { var template = ejs.compile(source, opts); // Beautify javascript code - if (!this.minimize && opts.beautify !== false) { - var ast = UglifyJS.parse(template.toString()); - ast.figure_out_scope(); - template = ast.print_to_string({beautify: true}); + if (this.loaders.length > 1) { + template = JSON.stringify(template()); + } else { + if (!this.minimize && opts.beautify !== false) { + var ast = UglifyJS.parse(template.toString()); + ast.figure_out_scope(); + template = ast.print_to_string({beautify: true}); + } } - return 'module.exports = ' + template; }; From 1b7761e648b3d2c4961d97b94c561eff175523b6 Mon Sep 17 00:00:00 2001 From: rork Date: Wed, 18 Apr 2018 15:38:19 +0400 Subject: [PATCH 03/10] content update --- README.md | 12 ++---------- package.json | 14 +++++++------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 22f0c57..20f391d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ -# ejs-compiled-loader for webpack +# ejs-webpack-loader for webpack 4.x EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.com/mde/ejs) function to compile templates. -To use [EJS by tj](https://github.com/tj/ejs) use 1.x branch and 1.x.x versions. - ## Installation -`npm install ejs-compiled-loader` +`npm install ejs-webpack-loader` ## Usage @@ -41,12 +39,6 @@ module: { loaders: [ {test: /\.ejs$/, loader: 'ejs-compiled?htmlmin'} // enable here ] -}, -'ejs-compiled-loader': { - 'htmlmin': true, // or enable here - 'htmlminOptions': { - removeComments: true - } } ``` diff --git a/package.json b/package.json index 1e6e348..b0d5889 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "ejs-compiled-loader", + "name": "ejs-webpack-loader", "version": "2.2.0", - "description": "EJS webpack loader (without frontend dependencies)", + "description": "EJS webpack 4.x loader (without frontend dependencies)", "main": "index.js", "scripts": { "test": "cd test && ../node_modules/.bin/webpack && node bundle.js" }, "repository": { "type": "git", - "url": "https://github.com/bazilio91/ejs-compiled-loader.git" + "url": "https://github.com/rorkflash/ejs-webpack-loader" }, "keywords": [ "ejs", @@ -16,12 +16,12 @@ "loader", "template" ], - "author": "Vasily Ostanin ", + "author": "Ashot Gasparyan ", "license": "MIT", "bugs": { - "url": "https://github.com/bazilio91/ejs-compiled-loader/issues" + "url": "https://github.com/rorkflash/ejs-webpack-loader/issues" }, - "homepage": "https://github.com/bazilio91/ejs-compiled-loader", + "homepage": "https://github.com/rorkflash/ejs-webpack-loader", "dependencies": { "ejs": "^2.0.0", "html-minifier": "^3", @@ -31,6 +31,6 @@ }, "devDependencies": { "node-libs-browser": "^0.5.0", - "webpack": "^1.9.4" + "webpack": "^4.5.0" } } From fb2882b963729fb38798763fac3be05669c17e5f Mon Sep 17 00:00:00 2001 From: rork Date: Wed, 18 Apr 2018 16:37:37 +0400 Subject: [PATCH 04/10] content update --- README.md | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 20f391d..067d298 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,122 @@ EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.c `npm install ejs-webpack-loader` -## Usage +## Config Setup examples as module loader + +ejs example +```ejs + + + + + <%= title %> + + +

<%= someVar %>

+ + +``` + +webpack.config.js + +``` javascript + +const path = require('path'); + +const config = { + output: { + filename: 'my-first-webpack.bundle.js' + }, + module: { + rules: [ + { + test: /\.ejs$/, + use: [ + { + loader: "ejs-webpack-loader", + options: { + data: {title: "New Title", someVar:"hello world"}, + htmlmin: true + } + } + ] + } + ] + } +}; + +``` + +## Config Setup examples with separate extractor + +``` javascript + +const path = require('path'); + +const config = { + entry: [ + './src/index.ejs', + './src/main.ejs', + ] + output: { + filename: 'my-first-webpack.bundle.js' + }, + module: { + rules: [ + { + test: /\.ejs$/, + use: [ + { + loader: 'file-loader', + options: { + name: '[name].html', + context: './src/', + outputPath: '/' + } + }, + { + loader: 'extract-loader' + }, + { + loader: "ejs-webpack-loader", + { + data: {title: "New Title", someVar:"hello world"}, + htmlmin: true + } + } + ] + } + ] + } +}; + +``` + +## Config Setup examples (via HtmlWebpackPlugin) + +``` javascript + +const path = require('path'); + +const config = { + output: { + filename: 'my-first-webpack.bundle.js' + }, + module: { + ... + }, + plugin: { + new HtmlWebpackPlugin({ + template: '!!ejs-webpack-loader!src/index.ejs' + }) + } +}; + +module.exports = config; + +``` + +## EJS Example [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) @@ -36,9 +151,19 @@ Following options can be specified in query: ```javascript module: { - loaders: [ - {test: /\.ejs$/, loader: 'ejs-compiled?htmlmin'} // enable here - ] + rules: [ + { + test: /\.ejs$/, + use: [ + { + loader: "ejs-webpack-loader", + options: { + htmlmin: true + } + } + ] + } + ] } ``` From 9e0e8aab0fbf6c6757f59f1bfe32768d7d22306e Mon Sep 17 00:00:00 2001 From: rork Date: Wed, 18 Apr 2018 16:40:19 +0400 Subject: [PATCH 05/10] 2.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0d5889..bdcde8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ejs-webpack-loader", - "version": "2.2.0", + "version": "2.2.1", "description": "EJS webpack 4.x loader (without frontend dependencies)", "main": "index.js", "scripts": { From d13a5d6fdb20021acc843f306b3e1e438ee79fe2 Mon Sep 17 00:00:00 2001 From: rork Date: Thu, 19 Apr 2018 00:14:52 +0400 Subject: [PATCH 06/10] update data pass function --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 70c49d8..648ad21 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ module.exports = function(source) { // Beautify javascript code if (this.loaders.length > 1) { - template = JSON.stringify(template()); + template = JSON.stringify(template((opts['data'] || {}))); } else { if (!this.minimize && opts.beautify !== false) { var ast = UglifyJS.parse(template.toString()); From b792693e4b14ef71ac4184a975ae4da2f8409faa Mon Sep 17 00:00:00 2001 From: Romain Gonord Date: Sun, 24 Feb 2019 15:22:42 +0100 Subject: [PATCH 07/10] add template dependencies to loader dependencies --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 648ad21..9ec1dbb 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ module.exports = function(source) { } var template = ejs.compile(source, opts); + template.dependencies.forEach(this.dependency.bind(this)); // Beautify javascript code if (this.loaders.length > 1) { From 409f0b1333af83406203926a288389b86fa611e1 Mon Sep 17 00:00:00 2001 From: Romain Gonord Date: Thu, 26 Sep 2019 11:35:13 +0200 Subject: [PATCH 08/10] declare ejs as peer dependency --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bdcde8e..e0621d7 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ }, "homepage": "https://github.com/rorkflash/ejs-webpack-loader", "dependencies": { - "ejs": "^2.0.0", "html-minifier": "^3", "loader-utils": "^0.2.7", "merge": "^1.2.0", @@ -32,5 +31,8 @@ "devDependencies": { "node-libs-browser": "^0.5.0", "webpack": "^4.5.0" + }, + "peerDependencies": { + "ejs": "^2.0.0" } } From 3c5edac01dc87e9b81dc0942f9809103d0322bc7 Mon Sep 17 00:00:00 2001 From: Kelly de Vries Date: Thu, 27 May 2021 15:29:24 -0700 Subject: [PATCH 09/10] Update merge npm due to high security vulnerability. --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e0621d7..b0d8c9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "ejs-webpack-loader", - "version": "2.2.1", + "name": "@kdv24/ejs-webpack-loader", + "version": "3.0.0", "description": "EJS webpack 4.x loader (without frontend dependencies)", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/rorkflash/ejs-webpack-loader" + "url": "git@github.com:kdv24/ejs-webpack-loader.git/main" }, "keywords": [ "ejs", @@ -16,16 +16,16 @@ "loader", "template" ], - "author": "Ashot Gasparyan ", + "author": "Kelly de Vries ", "license": "MIT", "bugs": { - "url": "https://github.com/rorkflash/ejs-webpack-loader/issues" + "url": "git@github.com:kdv24/ejs-webpack-loader.git/issues" }, - "homepage": "https://github.com/rorkflash/ejs-webpack-loader", + "homepage": "git@github.com:kdv24/ejs-webpack-loader.git", "dependencies": { "html-minifier": "^3", "loader-utils": "^0.2.7", - "merge": "^1.2.0", + "merge": "^2.1.1", "uglify-js": "~2.6.1" }, "devDependencies": { From 6e0758e9c46b51a1a61b6700686d88cd0975df1b Mon Sep 17 00:00:00 2001 From: Ashot Gasparyan Date: Sat, 12 Mar 2022 01:51:02 +0400 Subject: [PATCH 10/10] update credentials --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b0d8c9b..baf6b2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@kdv24/ejs-webpack-loader", - "version": "3.0.0", + "name": "ejs-webpack-loader", + "version": "2.2.2", "description": "EJS webpack 4.x loader (without frontend dependencies)", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git@github.com:kdv24/ejs-webpack-loader.git/main" + "url": "https://github.com/rorkflash/ejs-webpack-loader" }, "keywords": [ "ejs", @@ -16,12 +16,12 @@ "loader", "template" ], - "author": "Kelly de Vries ", + "author": "Ashot Gasparyan ", "license": "MIT", "bugs": { - "url": "git@github.com:kdv24/ejs-webpack-loader.git/issues" + "url": "https://github.com/rorkflash/ejs-webpack-loader/issues" }, - "homepage": "git@github.com:kdv24/ejs-webpack-loader.git", + "homepage": "https://github.com/rorkflash/ejs-webpack-loader", "dependencies": { "html-minifier": "^3", "loader-utils": "^0.2.7",