umd

Google closure compiler and UMD pattern

时间秒杀一切 提交于 2019-12-11 06:25:02
问题 I am developing a javascript library which uses closure compiler to combine/minify & typecheck. To avoid pouting global namespace I want to use UMD pattern & closue @export(or goog.exportSymbol('workspace', lkr.workspace) goog.provide('workspace'); goog.require('lkr.workspace'); /** * Exposed external access point * @export * @return {component} */ workspace = function() { return lkr.workspace.Core; } I have used an output-wrapper-file to generate the UMD wrapper //UMD bundling closure code

现代前端库开发指南系列(二):使用 webpack 构建一个库

匆匆过客 提交于 2019-12-09 22:02:11
前言 在前文中,我说过本系列文章的受众是在现代前端体系下能够熟练编写业务代码的同学,因此本文在介绍 webpack 配置时,仅提及构建一个库所特有的配置,其余配置请参考 webpack 官方文档。 输出产物 构建一个库与构建一个一般应用最大的不同点在于 构建完成后输出的产物 。 一般应用构建完成后会输出: 一个 html 文件 一个 js 入口 chunk 、若干子 chunk 若干 css 文件 若干其它资源,如图片、字体文件等 虽然输出的资源非常多,但实际上所有的依赖、加载关系都已经从 html 文件开始一层一层定下来了,换句话说,这个 html 文件实际上就是整个应用的入口。 一个库构建完成后会输出: 一个 CommonJS 格式的 js 文件 一个未压缩的 UMD 格式的 js 文件 一个已压缩的 UMD 格式的 js 文件 可能包括若干的 css 文件 可能包括若干的其它资源文件 库的入口分别是上面罗列的 js 文件;你可能会奇怪,一个库怎么会有3个入口文件呢?莫急,且听我一一道来。 CommonJS CommonJS 是 Node.js 推行的一种模块化规范,主要语法包括 module.exports 、 require() 等;而我们在使用 webpack 引入 npm 包时,实际上是处于 Node.js 环境,由此可知,这个 CommonJS 格式的入口 js 文件

Importing UMD built module using webpack leads to Critical Dependency errors

最后都变了- 提交于 2019-12-07 10:33:11
问题 I am trying to build a simple file that depends on a library built with UMD exports. // main.ts import { parseTree } from 'jsonc-parser'; const tree = parseTree('{ "name: "test" }'); console.log(tree); It compiles fine, however webpack spits out dependency errors: Hash: 85004e3e1bd3582666f5 Version: webpack 2.3.2 Time: 959ms Asset Size Chunks Chunk Names dist/bundle.js 61.8 kB 0 [emitted] main build/main.d.ts 0 bytes [emitted] [0] ./~/jsonc-parser/lib/main.js 40.1 kB {0} [built] [1] ./~/jsonc

Importing UMD built module using webpack leads to Critical Dependency errors

瘦欲@ 提交于 2019-12-05 14:54:23
I am trying to build a simple file that depends on a library built with UMD exports. // main.ts import { parseTree } from 'jsonc-parser'; const tree = parseTree('{ "name: "test" }'); console.log(tree); It compiles fine, however webpack spits out dependency errors: Hash: 85004e3e1bd3582666f5 Version: webpack 2.3.2 Time: 959ms Asset Size Chunks Chunk Names dist/bundle.js 61.8 kB 0 [emitted] main build/main.d.ts 0 bytes [emitted] [0] ./~/jsonc-parser/lib/main.js 40.1 kB {0} [built] [1] ./~/jsonc-parser/lib 160 bytes {0} [built] [2] ./~/path-browserify/index.js 6.18 kB {0} [built] [3] ./~/process

How to create angular2 library which could be supported by all script loaders

ぃ、小莉子 提交于 2019-12-03 11:36:41
How can I create a javascript file that contains an Angular 2 module that can be used by other applications, but is loaded at runtime directly from a centralized server and is NOT bundled into a specific application's code? Think of this as a CDN for an Angular 2 library. The requirement is that the consumers of this library will include a single script on their page. It is a requirement to implement it this way, so I am not interested in any answers that suggest bundling the library into the individual application's output files. The library script must be loaded directly from the library's

Lodash - '_' refers to a UMD global and lodash.js is not a module errors

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I do nothing and add the type definition it works for jquery but lodash gets a '_' referes to a UMD global, but the current file is a module. Consider adding an import instead. If I try to import lodash with any combination of import call, I get lodash.js is not a module I tried to get help by asking a question here and it was closed because there was another answer for Angular (Angular 2). I really need a real answer so I'm re-posting with my own solutions, hoping someone will eventually help me understand this problem. In this case I am

Webpack 4 universal library target

柔情痞子 提交于 2019-11-30 11:05:53
According to the Webpack 4 documentation , if I specify libraryTarget: 'umd' it should result in the following output: (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["MyLibrary"] = factory(); else root["MyLibrary"] = factory(); })(typeof self !== 'undefined' ? self : this, function() { return _entry_return_; }); However, what I get is: (function

Building a JavaScript library, why use an IIFE this way?

余生长醉 提交于 2019-11-30 03:38:40
I have noticed a lot of libraries use this style below to define their library. I also notice that the first self invoking function has something to do with Require.js or AMD systems, they always have factory as an argument, I will look more into Require.js, always been into Browserify. Why is the main code passed into the end of the first self invoking function inside parentheses, is this is a closure, or just considered an anonymous function, I will dig deeper into both. What are the benefits to this? It looks like inside the closure the author passes a string , this , and a callback . Will

Webpack 4 universal library target

狂风中的少年 提交于 2019-11-29 16:43:49
问题 According to the Webpack 4 documentation, if I specify libraryTarget: 'umd' it should result in the following output: (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["MyLibrary"] = factory(); else root["MyLibrary"] = factory(); })(typeof self !== 'undefined' ? self : this,

Building a JavaScript library, why use an IIFE this way?

好久不见. 提交于 2019-11-28 22:59:17
问题 I have noticed a lot of libraries use this style below to define their library. I also notice that the first self invoking function has something to do with Require.js or AMD systems, they always have factory as an argument, I will look more into Require.js, always been into Browserify. Why is the main code passed into the end of the first self invoking function inside parentheses, is this is a closure, or just considered an anonymous function, I will dig deeper into both. What are the