Skip to content

Commit

Permalink
Use Rollup to build also as ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
abdonrd committed Nov 6, 2020
1 parent 301f634 commit 77080dc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const os = require('os');
const gql = require('./src');
import os from 'os';
import gql from './src';

// Takes `source` (the source GraphQL query string)
// and `doc` (the parsed GraphQL document) and tacks on
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "2.11.0",
"description": "A JavaScript template literal tag that parses GraphQL queries",
"main": "./lib/graphql-tag.umd.js",
"module": "./src/index.js",
"jsnext:main": "./src/index.js",
"module": "./lib/graphql-tag.js",
"jsnext:main": "./lib/graphql-tag.js",
"sideEffects": false,
"scripts": {
"bundle": "rollup -c && cp src/index.js.flow lib/graphql-tag.umd.js.flow",
Expand Down
23 changes: 17 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
export default {
input: 'src/index.js',
output: {
file: 'lib/graphql-tag.umd.js',
format: 'umd',
name: 'graphql-tag',
sourcemap: true
},
output: [
{
file: 'lib/graphql-tag.js',
format: 'esm',
sourcemap: true
},
{
file: 'lib/graphql-tag.umd.js',
format: 'umd',
globals: {
'graphql/language': 'language'
},
name: 'graphql-tag',
sourcemap: true,
exports: 'named'
}
],
onwarn
};

Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var parser = require('graphql/language/parser');

var parse = parser.parse;
import { parse } from 'graphql/language';

// Strip insignificant whitespace
// Note that this could do a lot more, such as reorder fields etc.
Expand Down Expand Up @@ -177,4 +175,4 @@ gql.disableFragmentWarnings = disableFragmentWarnings;
gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;

module.exports = gql;
export default gql;
7 changes: 4 additions & 3 deletions test/graphql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const gql = require('../src');
const loader = require('../loader');
const assert = require('chai').assert;
import { assert } from 'chai';

import gql from '../src';
import loader from '../loader';

describe('gql', () => {
it('parses queries', () => {
Expand Down

0 comments on commit 77080dc

Please sign in to comment.