Skip to content

Commit

Permalink
Merge pull request #245 from luisrudge/master
Browse files Browse the repository at this point in the history
Fix importing json and superagent
  • Loading branch information
ForsakenHarmony committed Dec 4, 2018
2 parents b0c4b88 + 8907c6f commit 1f23940
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,9 @@ node_modules
.DS_Store
*.log
.rpt2_cache
.rts2_cache_cjs
.rts2_cache_es
.rts2_cache_umd
build
dist
package-lock.json
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"rollup-plugin-commonjs": "^9.0.0",
"rollup-plugin-es3": "^1.1.0",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-postcss": "^1.6.1",
"rollup-plugin-preserve-shebang": "^0.1.6",
Expand Down
21 changes: 10 additions & 11 deletions src/index.js
Expand Up @@ -18,6 +18,7 @@ import brotliSize from 'brotli-size';
import prettyBytes from 'pretty-bytes';
import shebangPlugin from 'rollup-plugin-preserve-shebang';
import typescript from 'rollup-plugin-typescript2';
import json from 'rollup-plugin-json';
import flow from './lib/flow-plugin';
import logError from './log-error';
import { readFile, isDir, isFile, stdout, stderr } from './utils';
Expand Down Expand Up @@ -238,7 +239,6 @@ function createConfig(options, entry, format, writeMeta) {
aliases['.'] = './' + basename(options.output);
}

let useNodeResolve = true;
const peerDeps = Object.keys(pkg.peerDependencies || {});
if (options.external === 'none') {
// bundle everything (external=[])
Expand Down Expand Up @@ -350,6 +350,15 @@ function createConfig(options, entry, format, writeMeta) {
inject: false,
extract: !!writeMeta,
}),
nodeResolve({
module: true,
jsnext: true,
browser: options.target !== 'node',
}),
commonjs({
include: 'node_modules/**',
}),
json(),
useTypescript &&
typescript({
typescript: require('typescript'),
Expand Down Expand Up @@ -419,16 +428,6 @@ function createConfig(options, entry, format, writeMeta) {
dangerousTaggedTemplateString: true,
},
}),
useNodeResolve &&
commonjs({
include: 'node_modules/**',
}),
useNodeResolve &&
nodeResolve({
module: true,
jsnext: true,
browser: options.target !== 'node',
}),
// We should upstream this to rollup
// format==='cjs' && replace({
// [`module.exports = ${rollupName};`]: '',
Expand Down
28 changes: 28 additions & 0 deletions test/__snapshots__/index.test.js.snap
Expand Up @@ -57,6 +57,34 @@ Build \\"basicCss\\" to dist:
135 B: basic-css.umd.js.br"
`;

exports[`fixtures basic-json 1`] = `
"Used script: microbundle
Directory tree:
basic-json
dist
basic-json.js
basic-json.js.map
basic-json.mjs
basic-json.mjs.map
basic-json.umd.js
basic-json.umd.js.map
package.json
src
index.js
two.json
Build \\"basicJson\\" to dist:
146 B: basic-json.js.gz
97 B: basic-json.js.br
145 B: basic-json.mjs.gz
98 B: basic-json.mjs.br
225 B: basic-json.umd.js.gz
161 B: basic-json.umd.js.br"
`;

exports[`fixtures basic-ts 1`] = `
"Used script: microbundle
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/basic-json/package.json
@@ -0,0 +1,3 @@
{
"name": "basic-json"
}
5 changes: 5 additions & 0 deletions test/fixtures/basic-json/src/index.js
@@ -0,0 +1,5 @@
import two from './two.json';

export default async function(...args) {
return two;
}
3 changes: 3 additions & 0 deletions test/fixtures/basic-json/src/two.json
@@ -0,0 +1,3 @@
{
"test": "true"
}

0 comments on commit 1f23940

Please sign in to comment.