npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-transform-nej-modules-es2015

v2.1.0

Published

转化 nej 代码至 commonjs

Downloads

27

Readme

babel-plugin-transform-nej-modules-es2015

Build Status 将NEJ转换成ES6的babel插件

安装

npm i babel-plugin-transform-nej-modules-es2015 --save-dev

使用

配置文件

plugins: [
    ['babel-plugin-transform-nej-modules-es2015', {
        // 项目的根目录地址
        // *注意是项目的根目录地址, 不是源码的根目录地址*
        // 用于将 define 中使用的 alias 转换成文件间的相对路径
        root: path.join(__dirname, 'src'),
        // nej alias
        alias: {
            pro: 'src/javascript'
        }
    }]
]

转换规则

转换的核心是通过babel的语法解析后,将define中的依赖通过一定的规则转换成ES6

事先约定: define([source1, sorurce2, …], functuin(nam1, name2, ….) {});

转换规则如下

  1. NEJ 的内置模块

    // NEJ code
    define([
       'base/klass',
       'base/element',
       'base/event'
    ], function (_k, _e, _v) {
      // code
    })
    
    // ES6 code
    import _k from 'nejm/base/klass';
    import _e from 'nejm/base/element';
    import _v from 'nejm/base/event';
  2. 文本模块

    // NEJ code
    define([
        'text!./jobLeftBar.html',
        'text!./jobLeftBar.css'
    ], function (_tpl, _css) {
      // code
    })
    
    // ES6 code
    import * as _tpl from './jobLeftBar.html';
    import * as _css from './jobLeftBar.css';
  3. 自定义模块

    TODO: 添加讲解

  4. NEJ注入变量

    转换时根据NEJ的注入规则, 在生成文件中添加对应语句.

    // NEJ code
    define(function(_p, _o, _f, _r){
      // code 
    })
    
    // ES6 code
    let _p = {};
    let _o = {};
    let _f = function() { };
    let _r = [];
    
    
    // 如果function没有return语句
    export defalut _p;

示例代码

TODO: 添加示例仓库

参与开发

  1. 发现:bug:或者有需求可以在issue中提出
  2. 贡献代码的话请fork后以pull request的方式提交

觉得这个插件不错的话请给个:star: