Skip to content

Commit 1da49e2

Browse files
committed
ADD: rollup build.js file, revision README.md; remove arrow function in src
1 parent 147a078 commit 1da49e2

13 files changed

+1563
-17
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
2-
dist
32
*.log

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,23 @@ m_j2c( obj, document.querySelector('#some_ul') ) //apply j2c style to #some_ul
2323

2424
This will do 3 things in order:
2525

26-
**1. insert `style` tag into `header`, which contains css:**
26+
1. insert `style` tag into `header`, which contains css:
2727
````CSS
2828
.item_j2c_qh10fm_1imf8sp_8nqwug_810slq_6 li{
2929
float:left;
3030
}
3131
````
3232

33-
**2. cache the generated style name && dom ref**
34-
35-
**3. replace all `.item` class into `.item_j2c_qh10fm_1imf8sp_8nqwug_810slq_6` in `#some_ul` and it's children**
33+
2. `#some_ul` and it's children, change `.item` class into `.item_j2c_qh10fm_1imf8sp_8nqwug_810slq_6`
34+
3. cache the generated style name && dom ref
3635

3736

3837

3938
## Benefit
4039

4140
- **no css name conflict**, all class is localized! ( powered by [j2c](https://github.com/j2css/j2c) )
42-
- apply **js computation to CSS**!
43-
- add css **namespaces** to a page/dom, switch using a js call
41+
- **js object computation to CSS**!
42+
- add css **namespaces** to a page/dom, a js function call to switch
4443

4544

4645

build.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var fs = require( 'fs' )
2+
var zlib = require( 'zlib' )
3+
var rollup = require( 'rollup' )
4+
var uglify = require('uglify-js')
5+
6+
// **** build.js modified from pygy's j2c project *****
7+
8+
var roll = rollup.rollup({
9+
entry: 'src/m_j2c.js'
10+
})
11+
12+
var formats = {
13+
amd:'amd',
14+
cjs:'commonjs',
15+
es6:'es6',
16+
umd:'umd',
17+
iife:'global',
18+
}
19+
Object.keys(formats).forEach(function(format){
20+
roll.then( function ( bundle ) {
21+
var name = formats[format]
22+
var result = bundle.generate({
23+
// output format - 'amd', 'cjs', 'es6', 'iife', 'umd'
24+
format: format,
25+
moduleId: 'm_j2c',
26+
moduleName: 'm_j2c',
27+
});
28+
fs.writeFileSync( 'dist/m_j2c_'+ name +'.js', result.code );
29+
30+
if(format!=='iife') return; // only minify for global
31+
32+
var minified = uglify.minify(result.code, {
33+
fromString: true,
34+
mangle: true,
35+
compress: {}
36+
}).code
37+
fs.writeFileSync('dist/m_j2c_' + name + '.min.js', minified)
38+
39+
zlib.gzip(minified, function(_, buf){
40+
console.log(name, _ || buf.length)
41+
fs.writeFileSync('dist/m_j2c_' + name + '.min.js.gz', buf)
42+
})
43+
44+
}).then(null, function (e) {console.log(format, e)})
45+
46+
})
47+
48+

dist/m_j2c.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)