Skip to content

Add support for webpack #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^1.0.0",
"karma-threshold-reporter": "^0.1.12",
"karma-webpack": "~1.7.0",
"lodash": "^4.1.0",
"matchdep": "^1.0.0",
"phantomjs-prebuilt": "^2.1.3",
"plato": "^1.5.0",
"run-browser": "^2.0.2",
"semantic-release": "^6.2.0",
"tape": "^4.4.0"
"tape": "^4.4.0",
"webpack": "~1.12.13"
},
"scripts": {
"test": "npm run test-browserify && gulp",
"test": "npm run test-browserify && npm run test-webpack && gulp",
"test-browserify": "run-browser test/commonjs/browserify.test.js -b",
"test-webpack": "karma start test/commonjs/webpack/karma.conf.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
Expand Down
17 changes: 10 additions & 7 deletions src/js/datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
* @since 2013-Jul-8
*/

(function (factory) {
(function (root, factory) {
'use strict';
/* istanbul ignore if */
if (typeof define === 'function' && /* istanbul ignore next */ define.amd) {
define(['angular', 'moment'], factory); // AMD
if (typeof module !== 'undefined' && module.exports) {
var ng = typeof angular === 'undefined' ? require('angular') : angular;
var mt = typeof moment === 'undefined' ? require('moment') : moment;
factory(ng, mt);
module.exports = 'ui.bootstrap.datetimepicker';
/* istanbul ignore next */
} else if (typeof exports === 'object') {
module.exports = factory(require('angular'), require('moment')); // CommonJS
} else if (typeof define === 'function' && /* istanbul ignore next */ define.amd) {
define(['angular', 'moment'], factory);
} else {
factory(window.angular, window.moment); // Browser global
factory(root.angular, root.moment);
}
}(function (angular, moment) {
}(this, function (angular, moment) {
'use strict';
angular.module('ui.bootstrap.datetimepicker', [])
.service('dateTimePickerConfig', DateTimePickerConfigProvider)
Expand Down
5 changes: 5 additions & 0 deletions test/commonjs/webpack/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* globals require */
var angular = require('angular');

angular.module('app', []);

70 changes: 70 additions & 0 deletions test/commonjs/webpack/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* globals require */
/* jshint node:true */

var webpackConfig = require('./webpack.config');

module.exports = function(config) {
'use strict';
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [{
pattern: 'webpack.test.js',
watched: false,
included: true,
served: true
}],

// webpack configuration
webpack: webpackConfig,

// webpack middlewae configuration
webpackMiddleware: { noInfo: true },

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'webpack.test.js': ['webpack']
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};
9 changes: 9 additions & 0 deletions test/commonjs/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* jshint node:true */

module.exports = {
entry: ['./test/commonjs/webpack/app.js'],
output: {
path: __dirname,
filename: 'bundle.js'
}
};
19 changes: 19 additions & 0 deletions test/commonjs/webpack/webpack.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* globals require */

require('angular');
describe('webpack require', function () {
'use strict';

function loadModule() {
angular.module('ui.bootstrap.datetimepicker');
}

it('should throw an error if the module is not defined', function () {
expect(loadModule).toThrow();
});

it('should be available when required', function () {
require('../../../');
expect(loadModule).not.toThrow();
});
});