From 249a4b4be10c6ad4179c6c09f1a742babbf3d3c5 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Tue, 22 Jan 2019 11:28:01 +0100 Subject: [PATCH] feat(rollup): configure default options for rollup-node-resolve plugin (browser and extensions) (#199) The most important here is `browser: true`. Without that, Rollup will bundle for Node.js and so it will expect we run the bundle with Node.js, but that's not our case. ![selection_117](https://user-images.githubusercontent.com/2103975/51528607-50414480-1e37-11e9-83cf-39d1923fd168.png) ![selection_118](https://user-images.githubusercontent.com/2103975/51528610-520b0800-1e37-11e9-9ec5-01ae9f6848e1.png) --- lib/options.ts | 6 ++- .../src/components/button/index.js | 2 +- .../__snapshots__/configuration.spec.ts.snap | 48 +++++++++++++++++-- .../commands/__snapshots__/build.spec.ts.snap | 4 +- .../commands/__snapshots__/lint.spec.ts.snap | 4 +- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/lib/options.ts b/lib/options.ts index 4e5c8bcd..2a3fe1ae 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -37,7 +37,11 @@ export function defaults(): ProjectOptions { handlers: { sass: {}, rollup: { - nodeResolve: {}, // https://github.com/rollup/rollup-plugin-node-resolve + nodeResolve: { + module: true, + browser: true, + extensions: ['.mjs', '.js', '.json', '.node', '.vue'], + }, // https://github.com/rollup/rollup-plugin-node-resolve commonjs: {}, // https://github.com/rollup/rollup-plugin-commonjs json: {}, // https://github.com/rollup/rollup-plugin-json#usage vue: {}, // https://rollup-plugin-vue.vuejs.org/options.html#options diff --git a/test/spec/__fixtures__/src/components/button/index.js b/test/spec/__fixtures__/src/components/button/index.js index 59e852aa..3b9337b5 100644 --- a/test/spec/__fixtures__/src/components/button/index.js +++ b/test/spec/__fixtures__/src/components/button/index.js @@ -1,5 +1,5 @@ import Vue from 'vue'; -import Button from './Button.vue'; +import Button from './Button'; Vue.component('y-button', Button); diff --git a/test/spec/api/__snapshots__/configuration.spec.ts.snap b/test/spec/api/__snapshots__/configuration.spec.ts.snap index dfdc5068..0b6f5670 100644 --- a/test/spec/api/__snapshots__/configuration.spec.ts.snap +++ b/test/spec/api/__snapshots__/configuration.spec.ts.snap @@ -72,7 +72,17 @@ Object { "rollup": Object { "commonjs": Object {}, "json": Object {}, - "nodeResolve": Object {}, + "nodeResolve": Object { + "browser": true, + "extensions": Array [ + ".mjs", + ".js", + ".json", + ".node", + ".vue", + ], + "module": true, + }, "shims": Object {}, "vue": Object {}, }, @@ -125,7 +135,17 @@ Object { "rollup": Object { "commonjs": Object {}, "json": Object {}, - "nodeResolve": Object {}, + "nodeResolve": Object { + "browser": true, + "extensions": Array [ + ".mjs", + ".js", + ".json", + ".node", + ".vue", + ], + "module": true, + }, "shims": Object {}, "vue": Object {}, }, @@ -221,7 +241,17 @@ Object { "rollup": Object { "commonjs": Object {}, "json": Object {}, - "nodeResolve": Object {}, + "nodeResolve": Object { + "browser": true, + "extensions": Array [ + ".mjs", + ".js", + ".json", + ".node", + ".vue", + ], + "module": true, + }, "shims": Object {}, "vue": Object {}, }, @@ -274,7 +304,17 @@ Object { "rollup": Object { "commonjs": Object {}, "json": Object {}, - "nodeResolve": Object {}, + "nodeResolve": Object { + "browser": true, + "extensions": Array [ + ".mjs", + ".js", + ".json", + ".node", + ".vue", + ], + "module": true, + }, "shims": Object {}, "vue": Object {}, }, diff --git a/test/spec/api/commands/__snapshots__/build.spec.ts.snap b/test/spec/api/commands/__snapshots__/build.spec.ts.snap index 6b860628..72007d9e 100644 --- a/test/spec/api/commands/__snapshots__/build.spec.ts.snap +++ b/test/spec/api/commands/__snapshots__/build.spec.ts.snap @@ -26,7 +26,7 @@ exports[`command: build lint (and fix) before build should lint (and but fix) fi exports[`command: build lint (and fix) before build should lint (and but fix) files built with handler \`rollup\`, before building them: button/index.js after lint 1`] = ` "import Vue from 'vue'; -import Button from './Button.vue'; +import Button from './Button'; Vue.component('y-button', Button); @@ -36,7 +36,7 @@ console.log(\\"Hello from index.js!\\"); exports[`command: build lint (and fix) before build should lint (and but fix) files built with handler \`rollup\`, before building them: button/index.js before lint 1`] = ` "import Vue from 'vue'; -import Button from './Button.vue'; +import Button from './Button'; Vue.component('y-button', Button); diff --git a/test/spec/api/commands/__snapshots__/lint.spec.ts.snap b/test/spec/api/commands/__snapshots__/lint.spec.ts.snap index 341c8d2c..90b6f972 100644 --- a/test/spec/api/commands/__snapshots__/lint.spec.ts.snap +++ b/test/spec/api/commands/__snapshots__/lint.spec.ts.snap @@ -26,7 +26,7 @@ exports[`command: build lint (and fix) should lint and fix JS entries only: js/b exports[`command: build lint (and fix) should lint and fix Rollup entries only: button/index.js after lint 1`] = ` "import Vue from 'vue'; -import Button from './Button.vue'; +import Button from './Button'; Vue.component('y-button', Button); @@ -36,7 +36,7 @@ console.log(\\"Hello from index.js!\\"); exports[`command: build lint (and fix) should lint and fix Rollup entries only: button/index.js before lint 1`] = ` "import Vue from 'vue'; -import Button from './Button.vue'; +import Button from './Button'; Vue.component('y-button', Button);