@ephox/swag
A collection of tools for rollup/webpack
Last updated 4 months ago by ephox .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ephox/swag 
SYNC missed versions from official npm registry.

This project contains various rollup plugins that is useful when dealing with es6 modules, as well as a grunt rollup task.

swag.nodeResolve

Resolves node module paths using memory caching. Other node resolver plugins will traverse the file system a lot and also load the package.json file for each package multiple times. This only does disk I/O once it also has support for remapping module paths based on prefixes.

swag.remapImports

Remaps module imports to the absolute module path by checking the import/exports on the main entry point module of a package.

So for example an local import of this: import { Arr } from '@ephox/katamari' would get remapped to import Arr from '/some/absolute/file/path' 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 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.

Example of usage

var swag = require('@ephox/swag');

export default {
  name: 'myModule',
  format: 'iife',
  banner: '(function () {',
  footer: '})()',
  plugins: [
    swag.nodeResolve({
      // Base dir to resolve paths from
      basedir: __dirname,

      // Replaces the prefixes with the specified replacement path
      prefixes: {
        'tinymce/core': 'src/core/dist/globals/tinymce/core',
        'tinymce/ui': 'lib/ui/main/ts'
      },

      // Maps resolved importees to new resolved importee paths
      mappers: [
        // Imports resolving to './lib/core/main/ts/api' gets replaced with './lib/globals/tinymce/core/api'
        swag.mappers.replaceDir('./lib/core/main/ts/api', './lib/globals/tinymce/core/api'),

        // Imports resolving to './lib/core/main/ts' throws an error
        swag.mappers.invalidDir('./lib/core/main/ts')
      ]
    }),
    swag.remapImports()
  ],
  input: 'lib/plugins/textpattern/src/main/ts/Plugin.js',
  output: {
    file: 'dist/textpattern/plugin.js',
    format: 'cjs'
  }
};

Using the webpack remapper loader

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.

module: {
  rules: [
    {
      test: /\.js|\.ts$/,
      use: ['@ephox/swag/webpack/remapper']
    },
    ....
  ]
}

Publishing & legal

  1. If you add new packages remember to re-generate the LEGAL.txt by running the ./bin/generate-legal.js script.
  2. Make sure that you also include the package-lock.json file since these needs to be in sync.

Current Tags

  • 4.1.4                                ...           latest (4 months ago)

14 Versions

  • 4.1.4                                ...           4 months ago
  • 4.1.3                                ...           4 months ago
  • 4.1.2                                ...           5 months ago
  • 4.1.1                                ...           6 months ago
  • 4.1.0                                ...           6 months ago
  • 4.0.1                                ...           6 months ago
  • 4.0.0                                ...           7 months ago
  • 3.0.2                                ...           10 months ago
  • 3.0.1                                ...           10 months ago
  • 3.0.0                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 17
Dependencies (9)
Dev Dependencies (13)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |