Skip to content

Commit

Permalink
Build our plugins in ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Aug 9, 2017
1 parent d5fad90 commit 4860f1c
Show file tree
Hide file tree
Showing 27 changed files with 4,479 additions and 13 deletions.
34 changes: 27 additions & 7 deletions build/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,36 @@ const files = {
Index: path.resolve(__dirname, '../js/src/index.js')
}

const pathDest = path.resolve(__dirname, '../js/dist/')
const relativePathSrc = 'js/src/'
const relativePathDist = 'js/dist/'
const externalIndex = []
const pathDest = path.resolve(__dirname, '../js/dist/')
const pathDestESM = path.resolve(__dirname, '../js/dist/esm/')
const relativePathSrc = 'js/src/'
const relativePathDist = 'js/dist/'
const relativePathDistESM = 'js/dist/esm/'
const externalIndex = []

for (const plugin in files) {
if (!Object.prototype.hasOwnProperty.call(files, plugin)) {
continue
}
const file = `${plugin.toLowerCase()}.js`
var externalArray = ['jquery', 'popper.js']

if (files[plugin] !== files.Util) {
externalArray.push(files.Util)
}
if (files[plugin] !== files.Tooltip) {

if (files[plugin] === files.Popover) {
externalArray.push(files.Tooltip)
}

// Do not export every plugins for the Index
if (files[plugin] !== files.Index) {
externalIndex.push(files[plugin])
}
else {
externalArray = externalIndex
}

rollup.rollup({
entry: files[plugin],
external: externalArray,
Expand All @@ -56,7 +63,7 @@ for (const plugin in files) {
}
})
.then(function (bundle) {
bundle.write({
const conf = {
dest: `${pathDest}/${file}`,
format: 'umd',
moduleName: plugin === 'Index' ? 'bootstrap' : plugin,
Expand All @@ -65,9 +72,22 @@ for (const plugin in files) {
jquery: '$',
'popper.js': 'Popper'
}
})
}
// Write plugin in UMD
bundle.write(conf)
.then(function () {
console.log(`${relativePathSrc}${file} -> ${relativePathDist}${file}`)

conf.format = 'es'
conf.moduleName = null
conf.dest = `${pathDestESM}/${file}`
conf.globals = null

// Write plugin in ESM
bundle.write(conf)
.then(function () {
console.log(`${relativePathSrc}${file} -> ${relativePathDistESM}${file}`)
})
})
})
.catch(console.error) // log errors
Expand Down
217 changes: 217 additions & 0 deletions js/dist/esm/alert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/dist/esm/alert.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4860f1c

Please sign in to comment.