Skip to content

Commit

Permalink
Upgrade to support rollup-0.48.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rj-hwang committed Mar 11, 2019
1 parent 2897369 commit 5519c45
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,75 @@ yarn add rollup-plugin-css-porter --dev

### Case 1 (default behavior):
Output to a standalone css file and a minified css file.
The output destination is the same dir with `bundle.write()` options.dest
The output destination is the same dir with `bundle.write()` options.file

```js
import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
entry: 'main.js',
input: 'main.js',
plugins: [ css() ]
}).then(bundle => {
bundle.write({
format: 'es',
dest: 'bundle.js'
file: 'bundle.js'
});
});
```

### Case 2:
Output to a standalone css file without minified css file.
The output destination is the same dir with `bundle.write()` options.dest
The output destination is the same dir with `bundle.write()` options.file

```js
import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
entry: 'main.js',
input: 'main.js',
plugins: [ css({minified: false}) ]
}).then(bundle => {
bundle.write({
format: 'es',
dest: 'bundle.js'
file: 'bundle.js'
});
});
```

### Case 3:
Output to a specific path if config the plugin options.dest
Output to a specific path if config the plugin options.file

```js
import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
entry: 'main.js',
input: 'main.js',
plugins: [ css({dest: 'path-to-my-dir/bundle.css'}) ]
}).then(bundle => {
bundle.write({
format: 'es',
dest: 'bundle.js'
file: 'bundle.js'
});
});
```

### Case 4:
Output to a standalone css file with only minified css file.
The output destination is the same dir with `bundle.write()` options.dest
The output destination is the same dir with `bundle.write()` options.file

```js
import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
entry: 'main.js',
input: 'main.js',
plugins: [ css({raw: false}) ]
}).then(bundle => {
bundle.write({
format: 'es',
dest: 'bundle.js'
file: 'bundle.js'
});
});
```
Expand All @@ -105,15 +105,15 @@ import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
entry: 'main.js',
input: 'main.js',
plugins: [ css({
raw: 'custom.css',
minified: 'custom.min.css',
}) ]
}).then(bundle => {
bundle.write({
format: 'es',
dest: 'bundle.js'
file: 'bundle.js'
});
});
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"clean": "rm -rf dist test/temp",
"test": "ava test/index.js",
"pretest": "npm run build",
"build": "rollup -c -f cjs -o dist/rollup-plugin-css-porter.cjs.js && rollup -c -f es -o dist/rollup-plugin-css-porter.es.js",
"build": "rollup -c --output.format cjs --output.file dist/rollup-plugin-css-porter.cjs.js && rollup -c --output.format es --output.file dist/rollup-plugin-css-porter.es.js",
"prepublish": "npm test"
},
"dependencies": {
Expand All @@ -40,7 +40,7 @@
},
"devDependencies": {
"ava": "^1.3.1",
"rollup": "^0.47.6",
"rollup": "^0.48.0",
"rollup-plugin-buble": "^0.19.6",
"rollup-watch": "^4.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import buble from 'rollup-plugin-buble';
var external = Object.keys(require('./package.json').dependencies);

export default {
entry: 'src/index.js',
input: 'src/index.js',
external: external,
plugins: [buble()]
};
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export default function(options = {}) {
const customRawName = typeof options.raw === 'string'
const customMinifiedName = typeof options.minified === 'string'

// the file of output: use this plugin options.dest or `bundle.write()` options.dest
let dest = options.dest || opts.dest
// the file of output: use this plugin options.dest or `bundle.write()` options.file
// 1. From 0.48.0+, the options param in bundle.write(options), options.dest rename to file
let dest = options.dest || opts.file
if (!dest && !customRawName && !customMinifiedName) return // output nothing if no dest config

// remove js module extname
Expand Down
20 changes: 10 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ test("should save to '.css' and '.min.css' file", async t => {
await fsp.remove(minifiedCssFile)

const bundle = await rollup({
entry: 'samples/main1.js',
input: 'samples/main1.js',
plugins: [css()]
})

await bundle.write({
format: 'es',
dest: jsFile
file: jsFile
});

t.true(await fsp.exists(jsFile))
Expand All @@ -54,13 +54,13 @@ test("should only save to '.css' file", async t => {
const minifiedCssFile = toDir + 'main.min.css'

const bundle = await rollup({
entry: 'samples/main1.js',
input: 'samples/main1.js',
plugins: [css({ minified: false })]
})

await bundle.write({
format: 'es',
dest: jsFile
file: jsFile
});

t.true(await fsp.exists(jsFile))
Expand All @@ -79,13 +79,13 @@ test("should only save to '.min.css' file", async t => {
const minifiedCssFile = toDir + 'main.min.css'

const bundle = await rollup({
entry: 'samples/main1.js',
input: 'samples/main1.js',
plugins: [css({ raw: false })]
})

await bundle.write({
format: 'es',
dest: jsFile
file: jsFile
});

t.true(await fsp.exists(jsFile))
Expand All @@ -104,13 +104,13 @@ test("should combine two css file and save to '.css' and '.min.css' file", async
const minifiedCssFile = toDir + 'main.min.css'

const bundle = await rollup({
entry: 'samples/main2.js',
input: 'samples/main2.js',
plugins: [css()]
})

await bundle.write({
format: 'es',
dest: jsFile
file: jsFile
});

t.true(await fsp.exists(cssFile))
Expand All @@ -133,7 +133,7 @@ test("should save to '.css' and '.min.css' file with custom names", async t => {
await fsp.remove(minifiedCssFile)

const bundle = await rollup({
entry: 'samples/main1.js',
input: 'samples/main1.js',
plugins: [css({
raw: customRawFile,
minified: customMinifiedFile,
Expand All @@ -142,7 +142,7 @@ test("should save to '.css' and '.min.css' file with custom names", async t => {

await bundle.write({
format: 'es',
dest: jsFile
file: jsFile
});

t.true(await fsp.exists(jsFile))
Expand Down

0 comments on commit 5519c45

Please sign in to comment.