Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 2362b81

Browse files
committed
chore(build): fix rollup build
Fix plugins order in `rollup` config Add inclusion of `node_modules` to commonjs plugin Add commonjs default export wrapper Remove fs.existsSync call Add `json` plugin in `rollup` config Add `babel-plugin-external-helpers` devDependency, add plugin to babel rollup config Update `rollup` and `rollup-plugin-babel` devDependencies Update config according to new `rollup` version Add `express` to globals in rollup config Add named `exports` to rollup config
1 parent 26d9d6b commit 2362b81

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const nuxtentModule = require("./dist/module.js");
2+
3+
module.exports = nuxtentModule.default;
4+
module.exports.meta = nuxtentModule.meta;

lib/module.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { existsSync } from 'fs'
21
import { resolve, join } from 'path'
32

43
import createRouter from './content/api'
@@ -12,13 +11,14 @@ const host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'lo
1211

1312
const nuxtentConfig = (nuxtOpts) => {
1413
const rootConfig = resolve(nuxtOpts.rootDir, 'nuxtent.config.js')
15-
if (existsSync(rootConfig)) {
16-
try {
17-
return require(rootConfig)
18-
} catch (err) {
19-
throw new Error (`[Invalid Nuxtent configuration] ${err}`)
14+
try {
15+
return require(rootConfig)
16+
} catch (err) {
17+
if (err.code === "MODULE_NOT_FOUND") {
18+
return nuxtOpts.nuxtent
2019
}
21-
} else return nuxtOpts.nuxtent
20+
throw new Error (`[Invalid Nuxtent configuration] ${err}`)
21+
}
2222
}
2323

2424
const contentOptions = (content, defaults) => {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nuxtent",
33
"version": "0.2.77",
44
"description": "Content Module for Nuxt.js.",
5-
"main": "dist/module.js",
5+
"main": "index.js",
66
"contributors": [
77
"Alid Castano (@alidcastano)"
88
],
@@ -52,12 +52,12 @@
5252
"@nuxtjs/axios": "^3.0.1",
5353
"ava": "^0.22.0",
5454
"babel-cli": "^6.26.0",
55+
"babel-plugin-external-helpers": "^6.22.0",
5556
"babel-plugin-istanbul": "^4.1.5",
5657
"babel-plugin-transform-async-to-generator": "^6.24.1",
5758
"babel-plugin-transform-object-rest-spread": "^6.26.0",
5859
"babel-plugin-transform-runtime": "^6.23.0",
5960
"babel-preset-es2015": "^6.24.1",
60-
"babel-preset-es2015-rollup": "^3.0.0",
6161
"babel-preset-stage-2": "^6.24.1",
6262
"babel-register": "^6.26.0",
6363
"chai": "^4.1.0",
@@ -71,8 +71,8 @@
7171
"mocha": "^3.5.0",
7272
"nuxt": "^1.0.0-rc11",
7373
"request-promise-native": "^1.0.4",
74-
"rollup": "^0.43.0",
75-
"rollup-plugin-babel": "^2.7.1",
74+
"rollup": "^0.50.0",
75+
"rollup-plugin-babel": "^3.0.2",
7676
"rollup-plugin-commonjs": "^8.0.2",
7777
"rollup-plugin-copy": "^0.2.3",
7878
"rollup-plugin-filesize": "^1.2.1",

rollup.config.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import resolve from 'rollup-plugin-node-resolve'
2+
import json from 'rollup-plugin-json'
23
import builtins from 'rollup-plugin-node-builtins'
34
import babel from 'rollup-plugin-babel'
45
import commonjs from 'rollup-plugin-commonjs'
@@ -9,21 +10,29 @@ import copy from 'rollup-plugin-copy'
910
const version = process.env.VERSION || require('./package.json').version
1011

1112
const corePlugins = () => [
12-
babel(),
1313
resolve(),
14-
commonjs(),
14+
commonjs({
15+
include: 'node_modules/**'
16+
}),
17+
babel({
18+
plugins: ['external-helpers']
19+
}),
1520
builtins(),
1621
uglify(),
1722
filesize()
1823
]
1924

2025
const bundle = (name, options) => ({
21-
entry: `lib/${name}.js`,
22-
dest: `dist/${name}.js`,
23-
format: 'umd',
24-
moduleName: `nuxtContent`,
26+
input: `lib/${name}.js`,
27+
output: {
28+
file: `dist/${name}.js`,
29+
format: 'cjs',
30+
exports: 'named'
31+
},
32+
name: `nuxtContent`,
2533
plugins: options.plugins || [],
2634
external: options.external || [],
35+
globals: options.globals || {},
2736
banner: `
2837
/**
2938
* Nuxt Content v${version}
@@ -36,6 +45,7 @@ const bundle = (name, options) => ({
3645
export default [
3746
bundle('module', {
3847
plugins: [
48+
json(),
3949
copy({
4050
'lib/plugin.js': 'dist/plugin.js',
4151
'lib/loader.js': 'dist/loader.js'
@@ -45,6 +55,9 @@ export default [
4555
external: [
4656
'express',
4757
'axios'
48-
]
58+
],
59+
globals: {
60+
express: 'express'
61+
}
4962
})
5063
]

0 commit comments

Comments
 (0)