]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
feat(plugins): allow to import separate plugins
authorJohann-S <johann.servoire@gmail.com>
Wed, 27 Jun 2018 09:33:07 +0000 (11:33 +0200)
committerJohann-S <johann.servoire@gmail.com>
Thu, 19 Jul 2018 17:59:45 +0000 (19:59 +0200)
.babelrc.js
build/build-plugins.js [new file with mode: 0644]
package-lock.json
package.json
site/docs/4.1/getting-started/javascript.md
site/docs/4.1/getting-started/webpack.md

index a4ef8cb6df6547918b34a2a54f8f50a705fe28d3..3dba11bd9fba8417314d4ed066bae6055c5750f3 100644 (file)
@@ -10,9 +10,8 @@ module.exports = {
     ]
   ],
   plugins: [
-    process.env.PLUGINS && 'transform-es2015-modules-strip',
     '@babel/proposal-object-rest-spread'
-  ].filter(Boolean),
+  ],
   env: {
     test: {
       plugins: [ 'istanbul' ]
diff --git a/build/build-plugins.js b/build/build-plugins.js
new file mode 100644 (file)
index 0000000..22a1790
--- /dev/null
@@ -0,0 +1,81 @@
+/*!
+ * Script to build our plugins to use them separately.
+ * Copyright 2018 The Bootstrap Authors
+ * Copyright 2018 Twitter, Inc.
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ */
+
+'use strict'
+
+const rollup  = require('rollup')
+const path    = require('path')
+const babel   = require('rollup-plugin-babel')
+const TEST    = process.env.NODE_ENV === 'test'
+
+const plugins = [
+  babel({
+    exclude: 'node_modules/**', // Only transpile our source code
+    externalHelpersWhitelist: [ // Include only required helpers
+      'defineProperties',
+      'createClass',
+      'inheritsLoose',
+      'defineProperty',
+      'objectSpread'
+    ]
+  })
+]
+
+const format = 'umd'
+const rootPath = !TEST ? '../js/dist/' : '../js/coverage/dist/'
+const bsPlugins = {
+  Alert: path.resolve(__dirname, '../js/src/alert.js'),
+  Button: path.resolve(__dirname, '../js/src/button.js'),
+  Carousel: path.resolve(__dirname, '../js/src/carousel.js'),
+  Collapse: path.resolve(__dirname, '../js/src/collapse.js'),
+  Dropdown: path.resolve(__dirname, '../js/src/dropdown.js'),
+  Modal: path.resolve(__dirname, '../js/src/modal.js'),
+  Popover: path.resolve(__dirname, '../js/src/popover.js'),
+  ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'),
+  Tab: path.resolve(__dirname, '../js/src/tab.js'),
+  Tooltip: path.resolve(__dirname, '../js/src/tooltip.js'),
+  Util: path.resolve(__dirname, '../js/src/util.js')
+}
+
+Object.keys(bsPlugins)
+  .forEach((pluginKey) => {
+    console.log(`Building ${pluginKey} plugin...`)
+
+    const external = ['jquery', 'popper.js']
+    const globals = {
+      jquery: 'jQuery', // Ensure we use jQuery which is always available even in noConflict mode
+      'popper.js': 'Popper'
+    }
+
+    // Do not bundle Util in plugins
+    if (pluginKey !== 'Util') {
+      external.push(bsPlugins.Util)
+      globals[bsPlugins.Util] = 'Util'
+    }
+
+    // Do not bundle Tooltip in Popover
+    if (pluginKey === 'Popover') {
+      external.push(bsPlugins.Tooltip)
+      globals[bsPlugins.Tooltip] = 'Tooltip'
+    }
+
+    rollup.rollup({
+      input: bsPlugins[pluginKey],
+      plugins,
+      external
+    }).then((bundle) => {
+      bundle.write({
+        format,
+        name: pluginKey,
+        sourcemap: true,
+        globals,
+        file: path.resolve(__dirname, `${rootPath}${pluginKey.toLowerCase()}.js`)
+      })
+        .then(() => console.log(`Building ${pluginKey} plugin... Done !`))
+        .catch((err) => console.error(`${pluginKey}: ${err}`))
+    })
+  })
index b326e499836dc02942dd9869a40f532b4dcd0cd4..2c847da12c4e3649ef573fec4ad2088a698477da 100644 (file)
       "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=",
       "dev": true
     },
-    "babel-plugin-transform-es2015-modules-strip": {
-      "version": "0.1.1",
-      "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-strip/-/babel-plugin-transform-es2015-modules-strip-0.1.1.tgz",
-      "integrity": "sha1-c5PwccNWod+2rAMHfgwGy1ejEl8=",
-      "dev": true
-    },
     "babel-polyfill": {
       "version": "6.23.0",
       "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz",
         "balanced-match": {
           "version": "1.0.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
         "code-point-at": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "concat-map": {
           "version": "0.0.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "console-control-strings": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "core-util-is": {
           "version": "1.0.2",
         "inherits": {
           "version": "2.0.3",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "ini": {
           "version": "1.3.5",
           "version": "1.0.0",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
           "version": "3.0.4",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
         "minimist": {
           "version": "0.0.8",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "minipass": {
           "version": "2.2.4",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.1",
             "yallist": "^3.0.0"
           "version": "0.5.1",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
         "number-is-nan": {
           "version": "1.0.1",
           "bundled": true,
-          "dev": true
+          "dev": true,
+          "optional": true
         },
         "object-assign": {
           "version": "4.1.1",
           "version": "1.4.0",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "wrappy": "1"
           }
           "version": "1.0.2",
           "bundled": true,
           "dev": true,
+          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
index 3773070a57db22da45fd289818ad89d6ccd31d40..23d799e4b6ff6e40fd80910befb5954263f1c8e0 100644 (file)
@@ -44,8 +44,8 @@
     "js-compile": "npm-run-all --parallel js-compile-* --sequential js-copy",
     "js-compile-standalone": "rollup --environment BUNDLE:false --config build/rollup.config.js --sourcemap",
     "js-compile-bundle": "rollup --environment BUNDLE:true --config build/rollup.config.js --sourcemap",
-    "js-compile-plugins": "cross-env PLUGINS=true babel js/src/ --out-dir js/dist/ --source-maps",
-    "js-compile-plugins-coverage": "cross-env PLUGINS=true NODE_ENV=test babel js/src/ --out-dir js/coverage/dist/ --source-maps",
+    "js-compile-plugins": "node build/build-plugins.js",
+    "js-compile-plugins-coverage": "cross-env NODE_ENV=test node build/build-plugins.js",
     "js-minify": "npm-run-all --parallel js-minify-*",
     "js-minify-standalone": "uglifyjs --compress typeofs=false --mangle --comments \"/^!/\" --source-map \"content=dist/js/bootstrap.js.map,includeSources,url=bootstrap.min.js.map\" --output dist/js/bootstrap.min.js dist/js/bootstrap.js",
     "js-minify-bundle": "uglifyjs --compress typeofs=false --mangle --comments \"/^!/\" --source-map \"content=dist/js/bootstrap.bundle.js.map,includeSources,url=bootstrap.bundle.min.js.map\" --output dist/js/bootstrap.bundle.min.js dist/js/bootstrap.bundle.js",
     "autoprefixer": "^8.6.5",
     "babel-eslint": "^8.2.5",
     "babel-plugin-istanbul": "^4.1.6",
-    "babel-plugin-transform-es2015-modules-strip": "^0.1.1",
     "broken-link-checker": "^0.7.8",
     "bundlesize": "^0.15.3",
     "clean-css-cli": "^4.1.11",
index da7011e76f0c00a2c08a580a8f26980bb573b2fe..20500c2af628c3b937430264dc0607eb1cc79ee4 100644 (file)
@@ -8,7 +8,9 @@ toc: true
 
 ## Individual or compiled
 
-Plugins can be included individually (using Bootstrap's individual `*.js` files), or all at once using `bootstrap.js` or the minified `bootstrap.min.js` (don't include both).
+Plugins can be included individually (using Bootstrap's individual `js/dist/*.js`), or all at once using `bootstrap.js` or the minified `bootstrap.min.js` (don't include both).
+
+If you use a bundler (Webpack, Rollup...), you can use `/js/dist/*.js` files which are UMD ready.
 
 ## Dependencies
 
index e8a57cf9667a027260f747255a5ca70a6e4d071c..59211b075d1d3637e4761e2194f50842ae7d0b7d 100644 (file)
@@ -22,7 +22,7 @@ Alternatively, you may **import plugins individually** as needed:
 
 {% highlight js %}
 import 'bootstrap/js/dist/util';
-import 'bootstrap/js/dist/dropdown';
+import 'bootstrap/js/dist/alert';
 ...
 {% endhighlight %}
 
@@ -30,11 +30,6 @@ Bootstrap is dependent on [jQuery](https://jquery.com/) and [Popper](https://pop
 these are defined as `peerDependencies`, this means that you will have to make sure to add both of them
 to your `package.json` using `npm install --save jquery popper.js`.
 
-{% capture callout %}
-Notice that if you chose to **import plugins individually**, you must also install [exports-loader](https://github.com/webpack-contrib/exports-loader)
-{% endcapture %}
-{% include callout.html content=callout type="warning" %}
-
 ## Importing Styles
 
 ### Importing Precompiled Sass