mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-17 09:52:29 +01:00
Merge pull request #13824 from jsdf/node-requirable
Allow npm package to be resolved via node module resolution
This commit is contained in:
commit
0521913a99
@ -26,6 +26,7 @@ module.exports = function (grunt) {
|
||||
return { sections: parser.parseFile() };
|
||||
};
|
||||
var generateRawFiles = require('./grunt/bs-raw-files-generator.js');
|
||||
var generateCommonJSModule = require('./grunt/bs-commonjs-generator.js');
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
@ -444,7 +445,7 @@ module.exports = function (grunt) {
|
||||
grunt.registerTask('test-js', ['jshint:core', 'jshint:test', 'jshint:grunt', 'jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']);
|
||||
|
||||
// JS distribution task.
|
||||
grunt.registerTask('dist-js', ['concat', 'uglify:core']);
|
||||
grunt.registerTask('dist-js', ['concat', 'uglify:core', 'commonjs']);
|
||||
|
||||
// CSS distribution task.
|
||||
grunt.registerTask('less-compile', ['less:compileCore', 'less:compileTheme']);
|
||||
@ -469,6 +470,12 @@ module.exports = function (grunt) {
|
||||
generateRawFiles(grunt, banner);
|
||||
});
|
||||
|
||||
grunt.registerTask('commonjs', 'Generate CommonJS entrypoint module in dist dir.', function () {
|
||||
var srcFiles = grunt.config.get('concat.bootstrap.src');
|
||||
var destFilepath = 'dist/js/npm.js';
|
||||
generateCommonJSModule(grunt, srcFiles, destFilepath);
|
||||
});
|
||||
|
||||
// Docs task.
|
||||
grunt.registerTask('docs-css', ['autoprefixer:docs', 'autoprefixer:examples', 'csscomb:docs', 'csscomb:examples', 'cssmin:docs']);
|
||||
grunt.registerTask('lint-docs-css', ['csslint:docs', 'csslint:examples']);
|
||||
|
13
dist/js/npm.js
vendored
Normal file
13
dist/js/npm.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// This file is generated. You can require() it in a CommonJS environment.
|
||||
require('../../js/transition.js')
|
||||
require('../../js/alert.js')
|
||||
require('../../js/button.js')
|
||||
require('../../js/carousel.js')
|
||||
require('../../js/collapse.js')
|
||||
require('../../js/dropdown.js')
|
||||
require('../../js/modal.js')
|
||||
require('../../js/tooltip.js')
|
||||
require('../../js/popover.js')
|
||||
require('../../js/scrollspy.js')
|
||||
require('../../js/tab.js')
|
||||
require('../../js/affix.js')
|
23
grunt/bs-commonjs-generator.js
Normal file
23
grunt/bs-commonjs-generator.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var COMMONJS_BANNER = '// This file is generated. You can require() it in a CommonJS environment.\n';
|
||||
|
||||
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
|
||||
var destDir = path.dirname(destFilepath);
|
||||
|
||||
function srcPathToDestRequire(srcFilepath) {
|
||||
var requirePath = path.relative(destDir, srcFilepath);
|
||||
return 'require(\'' + requirePath + '\')';
|
||||
}
|
||||
|
||||
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
|
||||
try {
|
||||
fs.writeFileSync(destFilepath, moduleOutputJs);
|
||||
}
|
||||
catch (err) {
|
||||
grunt.fail.warn(err);
|
||||
}
|
||||
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
|
||||
};
|
@ -18,6 +18,7 @@
|
||||
},
|
||||
"style": "dist/css/bootstrap.css",
|
||||
"less": "less/bootstrap.less",
|
||||
"main": "./dist/js/npm",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twbs/bootstrap.git"
|
||||
|
Loading…
x
Reference in New Issue
Block a user