1 | # parcel-plugin-static-files-copy [![Build Status](https://travis-ci.org/elwin013/parcel-plugin-static-files-copy.svg?branch=master)](https://travis-ci.org/elwin013/parcel-plugin-static-files-copy)
|
2 |
|
3 | ParcelJS plugin to copy static files from some directory to directory with bundle.
|
4 |
|
5 | ## Install
|
6 |
|
7 | ```
|
8 | yarn add parcel-plugin-static-files-copy --dev
|
9 | ```
|
10 |
|
11 | ## Usage
|
12 |
|
13 | 1. Create `static` directory in you project root.
|
14 | 2. Fill it with your static files
|
15 | 3. Run build - and that's all!
|
16 |
|
17 | ## Customization
|
18 |
|
19 | Beyond the default settings, you can:
|
20 |
|
21 | 1. Name of the directory to be copied.
|
22 | 2. Copy multiple directory.
|
23 | 3. Copy different directory based on different output directory.
|
24 | 3. Watch for changes during development (rebuilding when necessary).
|
25 |
|
26 | ### Example
|
27 |
|
28 | The following configures the plugin to copy all files in `public` to the build directory and watch for changes in all source files (`**` is a deep wildcard).
|
29 |
|
30 | ```json
|
31 | // package.json
|
32 | {
|
33 | ...
|
34 | "staticFiles": {
|
35 | "staticPath": "public",
|
36 | "watcherGlob": "**"
|
37 | }
|
38 | }
|
39 | ```
|
40 |
|
41 | ### Multiple Static Directories
|
42 |
|
43 | To copy more than one directory to the build directory, specify `staticPath` as an array. The following copies `public` and `vendor/public`:
|
44 |
|
45 | ```json
|
46 | // package.json
|
47 | {
|
48 | ...
|
49 | "staticFiles": {
|
50 | "staticPath": ["public", "vendor/public"]
|
51 | }
|
52 | }
|
53 | ```
|
54 |
|
55 | ### Different source of static files based on output directory
|
56 |
|
57 | To copy different files (from different directories) based on output directory (e.g. `--out-dir dist1` and `--out-dir dist2`) make `staticPath` a object:
|
58 |
|
59 | ```json
|
60 | // package.json
|
61 | {
|
62 | ...
|
63 | "staticFiles": {
|
64 | "staticPath": [
|
65 | {
|
66 | "outDirPattern": "**/dist1",
|
67 | "staticPath": "static1"
|
68 | },
|
69 | {
|
70 | "outDirPattern": "**/dist2",
|
71 | "staticPath": "static2"
|
72 | }
|
73 | ]
|
74 | },
|
75 | }
|
76 | ```
|
77 |
|
78 | ### Watching for Changes
|
79 |
|
80 | Parcel can rebuild your bundle(s) whenever changes occur in the static directory. This is disabled by default, but it can be enabled by specifying a glob pattern for files that shoudl be watched.
|
81 |
|
82 | Note the relative file path is used in matching (not just the file name). To match filenames in deep directories, start with a "globstar" (double star). The plugin uses Node's built-in [Minimatch Library](https://github.com/isaacs/minimatch) for glob matching.
|
83 |
|
84 | The following watches all XML files in the static directory:
|
85 |
|
86 | ```json
|
87 | // package.json
|
88 | {
|
89 | ...
|
90 | "staticFiles": {
|
91 | "staticPath": "public",
|
92 | "watcherGlob": "**/*.xml"
|
93 | }
|
94 | }
|
95 | ```
|
96 |
|
97 | To disable watching, either remove the `"watcherGlob"` key (disabled is the default) or set it to false/null/undefined:
|
98 |
|
99 | ```json
|
100 | // package.json
|
101 | {
|
102 | ...
|
103 | "staticFiles": {
|
104 | "staticPath": "public",
|
105 | "watcherGlob": false
|
106 | }
|
107 | }
|
108 | ```
|
109 |
|
110 | ## Contribute
|
111 |
|
112 | You're interested in contributing? Awesome! Fork, make change, commit and create pull request. I'll do my best to merge changes!
|
113 |
|
114 | ## License
|
115 |
|
116 | [MIT](/LICENSE)
|