concat-text-webpack-plugin
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -23,6 +23,9 @@ "use strict"; | ||
const PLUGIN_NAME = "ConcatTextPlugin"; | ||
exports.PLUGIN_NAME = PLUGIN_NAME; | ||
const REGEXP_PLACEHOLDERS = /\[(name)\]/g; | ||
/** | ||
* Extract a file extension from a glob path. | ||
* If multiple file types are being matched by the glob (e.g. `*.{txt,properties}` | ||
* or `*.tsx?`), an empty string will be returned. | ||
* If multiple file types are being matched by the glob | ||
* (e.g. `*.{txt,properties}` or `*.ts?(x)`), an empty | ||
* string will be returned. | ||
* | ||
@@ -33,4 +36,2 @@ * @param {string} globPath The glob path from which to extract a file type extension. | ||
exports.PLUGIN_NAME = PLUGIN_NAME; | ||
function getExtFromGlobPath(globPath) { | ||
@@ -63,3 +64,3 @@ const extname = _path.default.extname(globPath); | ||
* `startingPath` (Webpacks `output.path`) and the configured `outputPath`. | ||
* If the `outputPath` is already a relative path, we'll just return it. | ||
* If the `outputPath` is already a relative path, we'll just return it. | ||
* Otherwise, if it is an absolute path, we determine its location as a | ||
@@ -98,2 +99,7 @@ * path relative to the `startingPath`. | ||
}; | ||
if (options.name && REGEXP_PLACEHOLDERS.test(options.name)) { | ||
options.name = options.name.replace(REGEXP_PLACEHOLDERS, basename); | ||
} | ||
return Object.assign({}, defaultOptions, options); | ||
@@ -100,0 +106,0 @@ } |
{ | ||
"name": "concat-text-webpack-plugin", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Concatenate and extract text files.", | ||
@@ -35,12 +35,12 @@ "main": "dist/cjs.js", | ||
"devDependencies": { | ||
"@babel/cli": "7.4.3", | ||
"@babel/core": "7.4.3", | ||
"@babel/preset-env": "7.4.3", | ||
"@namics/eslint-config": "6.1.0", | ||
"babel-eslint": "10.0.1", | ||
"babel-jest": "24.7.1", | ||
"eslint": "5.16.0", | ||
"eslint-plugin-import": "2.17.2", | ||
"jest": "24.7.1", | ||
"memory-fs": "0.4.1", | ||
"@babel/cli": "7.6.4", | ||
"@babel/core": "7.6.4", | ||
"@babel/preset-env": "7.6.3", | ||
"@namics/eslint-config": "8.0.2", | ||
"babel-eslint": "10.0.3", | ||
"babel-jest": "24.9.0", | ||
"eslint": "6.5.1", | ||
"eslint-plugin-import": "2.18.2", | ||
"jest": "24.9.0", | ||
"memory-fs": "0.5.0", | ||
"pkg-ok": "2.3.1", | ||
@@ -47,0 +47,0 @@ "rimraf": "2.6.3", |
@@ -1,5 +0,9 @@ | ||
# Concat Text Webpack Plugin | ||
[![NPM version][npm-badge]][npm-url] | ||
[![License][license-badge]][license-url] | ||
[![dependencies Status][deps-badge]][deps-url] | ||
The **ConcatTextPlugin** extracts and concatenates text files from a specified *glob* path into a single file. | ||
# concat-text-webpack-plugin | ||
The `ConcatTextPlugin` extracts and concatenates text files from a specified *glob* path into a single file. This is **not intended** to be used to extract frontend asset files, like stylesheets (use the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) for this). Instead, this plugin is helpful when dealing with raw text assets that have been split into multiple files for code modularisation purposes, but need to be consolidated for consumption by e.g. the project's backend system. | ||
## Usage | ||
@@ -36,2 +40,3 @@ | ||
files: "res/**/*", | ||
outputPath: "static" | ||
}) | ||
@@ -42,3 +47,3 @@ ] | ||
The example above will generate a concatenated file `dist/app` (without a file extension) containing everything under `res/`. The output file won't have a file extension as well if the `files` glob string matches multiple file types: | ||
The example above will generate a concatenated file `dist/static/app` (without a file extension) containing everything under `res/`. The output file won't have a file extension as well if the glob string matches multiple file types: | ||
@@ -54,2 +59,3 @@ ```js | ||
files: "res/**/*.{txt,properties}", | ||
outputPath: "static" | ||
}) | ||
@@ -62,6 +68,41 @@ ] | ||
So, if you want to explicitly set the file extension for the concatenated file while still matching multiple types, the `name` options needs to be set. However, in case you don't want to set a static file name and instead prefer to just use the `output.filename` option of your Webpack config, the **[name]** placeholder can be of help: | ||
```js | ||
module.exports = { | ||
output: { | ||
path: "dist/", | ||
filename: "app.js" | ||
}, | ||
plugins: [ | ||
new ConcatTextPlugin({ | ||
files: "res/**/*.{md,markdown}", | ||
outputPath: "docs", | ||
name: "[name].md" | ||
}) | ||
] | ||
} | ||
``` | ||
#### `outputPath` (string, default: same as *Webpack `output.path`*) | ||
Specify where the concatenated file should be placed, relative to the Webpack output path. You might also set it to an **absolute path**. | ||
Specify where the concatenated file should be placed, relative to the Webpack output path. You might also set it to an **absolute path**. Omitting this option will place the concatenated file at your Webpack output path. | ||
```js | ||
module.exports = { | ||
output: { | ||
path: "dist/", | ||
filename: "app.js" | ||
}, | ||
plugins: [ | ||
new ConcatTextPlugin({ | ||
files: "res/**/*.md", | ||
name: "docs.md" | ||
}) | ||
] | ||
} | ||
``` | ||
The configuration seen above will write a markdown file `dist/docs.md` containing every markdown file it could find under the `res/` directory. | ||
## Tests | ||
@@ -74,1 +115,12 @@ | ||
``` | ||
## License | ||
[MIT](./LICENSE) | ||
[npm-badge]: https://img.shields.io/npm/v/concat-text-webpack-plugin.svg | ||
[npm-url]: https://npmjs.org/package/concat-text-webpack-plugin | ||
[license-badge]: https://img.shields.io/badge/license-MIT-green.svg | ||
[license-url]: http://opensource.org/licenses/MIT | ||
[deps-badge]: https://david-dm.org/namics/webpack-concat-text-plugin/status.svg | ||
[deps-url]: https://david-dm.org/namics/webpack-concat-text-plugin |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11613
129
122
1