From c290d2ecb46f43fe21f7e442fb9ab6036e4bdc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Tue, 15 Oct 2019 14:05:20 +0800 Subject: [PATCH] Use Rollup to build also as ESM --- package.json | 4 ++-- rollup.config.js | 23 +++++++++++++++++------ src/index.js | 6 ++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 31b60532..be769977 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "2.10.1", "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", "scripts": { "bundle": "rollup -c && cp src/index.js.flow lib/graphql-tag.umd.js.flow", "test": "mocha test/graphql.js test/graphql-v0.12.js && tav --ci --compat", diff --git a/rollup.config.js b/rollup.config.js index 0e7f3de5..8833764a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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': 'graphql' + }, + name: 'graphql-tag', + sourcemap: true, + exports: 'named' + } + ], onwarn }; diff --git a/src/index.js b/src/index.js index f52711e4..bf4956d6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,4 @@ -var parser = require('graphql/language/parser'); - -var parse = parser.parse; +import { parse } from 'graphql'; // Strip insignificant whitespace // Note that this could do a lot more, such as reorder fields etc. @@ -177,4 +175,4 @@ gql.disableFragmentWarnings = disableFragmentWarnings; gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables; gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables; -module.exports = gql; +export default gql;