1 | This project contains various rollup plugins that is useful when dealing with es6 modules, as well as a grunt rollup task.
|
2 |
|
3 | ### swag.nodeResolve
|
4 |
|
5 | Resolves node module paths using memory caching. Other node resolver plugins will traverse the file system a lot and also load the package.json
|
6 | file for each package multiple times. This only does disk I/O once it also has support for remapping module paths based on prefixes.
|
7 |
|
8 | ### swag.remapImports
|
9 |
|
10 | Remaps module imports to the absolute module path by checking the import/exports on the main entry point module of a package.
|
11 |
|
12 | So for example an local import of this: `import { Arr } from '@ephox/katamari'` would get remapped to `import Arr from '/some/absolute/file/path'`
|
13 | this will reduce the amout of files included and also reduce output size since local variables created by function calls in the top level of a module
|
14 | would otherwise be included even though it wasn't used since JS isn't pure those calls could cause side effects and can't be removed.
|
15 |
|
16 | ### Example of usage
|
17 |
|
18 | ```js
|
19 | var swag = require('@ephox/swag');
|
20 |
|
21 | export default {
|
22 | name: 'myModule',
|
23 | format: 'iife',
|
24 | banner: '(function () {',
|
25 | footer: '})()',
|
26 | plugins: [
|
27 | swag.nodeResolve({
|
28 | // Base dir to resolve paths from
|
29 | basedir: __dirname,
|
30 |
|
31 | // Replaces the prefixes with the specified replacement path
|
32 | prefixes: {
|
33 | 'tinymce/core': 'src/core/dist/globals/tinymce/core',
|
34 | 'tinymce/ui': 'lib/ui/main/ts'
|
35 | },
|
36 |
|
37 | // Maps resolved importees to new resolved importee paths
|
38 | mappers: [
|
39 | // Imports resolving to './lib/core/main/ts/api' gets replaced with './lib/globals/tinymce/core/api'
|
40 | swag.mappers.replaceDir('./lib/core/main/ts/api', './lib/globals/tinymce/core/api'),
|
41 |
|
42 | // Imports resolving to './lib/core/main/ts' throws an error
|
43 | swag.mappers.invalidDir('./lib/core/main/ts')
|
44 | ]
|
45 | }),
|
46 | swag.remapImports()
|
47 | ],
|
48 | input: 'lib/plugins/textpattern/src/main/ts/Plugin.js',
|
49 | output: {
|
50 | file: 'dist/textpattern/plugin.js',
|
51 | format: 'cjs'
|
52 | }
|
53 | };
|
54 | ```
|
55 |
|
56 | ### Using the webpack remapper loader
|
57 |
|
58 | Add the remapper loader first to the list of webpack loaders this will then change all the imports to go directly to the api modules. It handles both ts files and js files.
|
59 |
|
60 | ```
|
61 | module: {
|
62 | rules: [
|
63 | {
|
64 | test: /\.js|\.ts$/,
|
65 | use: ['@ephox/swag/webpack/remapper']
|
66 | },
|
67 | ....
|
68 | ]
|
69 | }
|
70 | ```
|
71 |
|
72 | ### Publishing & legal
|
73 |
|
74 | 1. If you add new packages remember to re-generate the LEGAL.txt by running the `./bin/generate-legal.js` script.
|
75 | 2. Make sure that you also include the package-lock.json file since these needs to be in sync.
|