Skip to content

Commit

Permalink
new: Allow JSON files to be imported. (#34)
Browse files Browse the repository at this point in the history
* fix: Add `babelrcRoots` to root babel config.

* fix: Add `babelrcRoots` to root babel config.

* Start on.

* Add snapshots.

* Update docs.
  • Loading branch information
milesj authored Mar 7, 2021
1 parent 2fdc60a commit f7db2d1
Show file tree
Hide file tree
Showing 10 changed files with 979 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"@microsoft/api-extractor": "^7.13.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"babel-plugin-transform-async-to-promises": "^0.8.15",
"builtin-modules": "^3.2.0",
Expand Down
7 changes: 6 additions & 1 deletion src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import nodePolyfills from 'rollup-plugin-polyfill-node';
import visualizer from 'rollup-plugin-visualizer';
import { getBabelInputPlugin, getBabelOutputPlugin } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import { getBabelInputConfig, getBabelOutputConfig } from '../babel/config';
import type { BundleArtifact } from '../BundleArtifact';
import { EXCLUDE, EXTENSIONS } from '../constants';
import { BundleBuild, FeatureFlags, Format } from '../types';

const sharedPlugins = [resolve({ extensions: EXTENSIONS, preferBuiltins: true }), commonjs()];
const sharedPlugins = [
resolve({ extensions: EXTENSIONS, preferBuiltins: true }),
commonjs(),
json({ compact: true, namedExports: false }),
];

function getRollupModuleFormat(format: Format): ModuleFormat {
if (
Expand Down
8 changes: 8 additions & 0 deletions tests/__fixtures__/examples/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"list": ["foo", "bar", "baz"],
"number": 123,
"string": "abc",
"object": {
"foo": true
}
}
4 changes: 4 additions & 0 deletions tests/__fixtures__/examples/json-imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import data from './data.json';

export const keys = Object.keys(data);
1 change: 1 addition & 0 deletions tests/babel/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Object {
exports[`createRootConfig() returns the correct config 1`] = `
Object {
"babelrc": true,
"babelrcRoots": Array [],
"overrides": Array [
Object {
"presets": Array [
Expand Down
Loading

0 comments on commit f7db2d1

Please sign in to comment.