Skip to content
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

[RFR] Migrate from require to Webpack #428

Merged
merged 13 commits into from
May 22, 2015
Merged
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
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ dist
.sass-cache
src/javascripts/bower_components
src/javascripts/config.js
src/javascripts/test/fixtures/examples/blog
src/styles/*.css
build/require
build/es6
build/ng-admin-configuration.js
build/ng-admin.css
src/css
examples/blog/build
examples/blog/assets
npm-debug.log
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ addons:
#sudo: false
language: node_js
node_js:
- "0.10"
- "0.12"
before_install:
- "export TZ=Europe/Paris" # Change timezone to test Date function more accurately
- "export DISPLAY=:99.0"
Expand Down
221 changes: 28 additions & 193 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,162 +5,39 @@ module.exports = function (grunt) {

// Define the configuration for all the tasks
grunt.initConfig({
"babel": {
"options": {
"sourceMap": true,
"modules": "amd"
},
dist: {
files: [{
"cwd": "src/javascripts/ng-admin/es6/lib/",
"expand": true,
"src": "**/*.js",
"dest": "build/es6/",
"ext": ".js"
}]
}
},

requirejs: grunt.file.readJSON('grunt/grunt-requirejs.json'),
compass: grunt.file.readJSON('grunt/grunt-compass.json'),

ngAnnotate: {
ngadmin: {
files: {
'build/ng-admin.min.js': ['build/ng-admin.min.js']
}
}
},

cssmin: {
combine: {
files: {
'build/ng-admin.min.css': [
'build/ng-admin.css',
'src/javascripts/bower_components/nprogress/nprogress.css',
'src/javascripts/bower_components/humane/themes/flatty.css',
'src/javascripts/bower_components/textAngular/dist/textAngular.min.css',
'src/javascripts/bower_components/codemirror/lib/codemirror.css',
'src/javascripts/bower_components/codemirror/addon/lint/lint.css'
]
}
}
},

concat: {
css: {
src: [
'build/ng-admin.css',
'src/javascripts/bower_components/nprogress/nprogress.css',
'src/javascripts/bower_components/humane/themes/flatty.css',
'src/javascripts/bower_components/textAngular/dist/textAngular.min.css',
'src/javascripts/bower_components/codemirror/lib/codemirror.css',
'src/javascripts/bower_components/codemirror/addon/lint/lint.css'
],
dest: 'build/ng-admin.min.css'
}
},

uglify: {
ngadmin: {
options: {
sourceMap: true,
sourceMapName: 'build/ng-admin.min.map'
},
files: {
'build/ng-admin.min.js': ['build/ng-admin.min.js']
}
},
config: {
options: {
sourceMap: true,
sourceMapName: 'build/ng-admin-configuration.min.map'
},
files: {
'build/ng-admin-configuration.min.js': ['build/ng-admin-configuration.js']
}
}
},

clean : {
build : ["build/*", "!build/ng-admin.min.js", "!build/ng-admin.min.css", "!build/ng-admin.min.map"]
},

copy: {
css_dev: {
src: 'build/ng-admin.min.css',
dest: 'examples/blog/build/ng-admin.css',
options: {
process: function(content) {
return content.replace(/url\("\.\.\/src\/javascripts\/bower_components\/bootstrap-sass-official\/assets\/fonts\/bootstrap/g, 'url(".');
}
}
},
fonts_dev: {
cwd: 'src/javascripts/bower_components/bootstrap-sass-official/assets/fonts/bootstrap/',
src: ['**'],
dest: 'examples/blog/build/',
expand: true
test_build: {
src: 'build/*',
dest: 'src/javascripts/test/fixtures/examples/blog/'
},
assets_dev: {
cwd: 'assets/',
src: ['**'],
dest: 'examples/blog/assets/',
expand: true
},
js_dev: {
src: 'build/ng-admin.min.js',
dest: 'examples/blog/build/ng-admin.js'
},
css: {
src: 'build/ng-admin.min.css',
dest: 'examples/blog/build/ng-admin.min.css',
test_sample_app: {
src: 'examples/blog/*',
dest: 'src/javascripts/test/fixtures/',
options: {
process: function(content) {
return content.replace(/url\("\.\.\/src\/javascripts\/bower_components\/bootstrap-sass-official\/assets\/fonts\/bootstrap/g, 'url(".');
return content.replace(/http\:\/\/localhost\:8080\//g, '/');
}
}
},
angular: {
src: 'src/javascripts/bower_components/angular/angular.js',
dest: 'examples/blog/build/angular.js'
},
config: {
src: 'examples/blog/config.js',
dest: 'examples/blog/config.js',
options: {
process: function (content) {
return process.env.CI ? content.replace(/http:\/\/localhost:3000\//g, 'http://ng-admin.marmelab.com:8080/') : content;
}
}
},
es6: {
src: 'build/ng-admin-configuration.min.js',
dest: 'examples/blog/build/ng-admin-configuration.min.js'
},
es6_dev: {
src: 'build/ng-admin-configuration.js',
dest: 'examples/blog/build/ng-admin-configuration.min.js'
},
es6_devmap: {
cwd: 'build/es6/',
src: ['**/*.map'],
dest: 'examples/blog/build/',
expand: true
}
},

connect: {
server: {
dev: {
options: {
port: 8000,
base: 'examples/blog/',
keepalive: false,
livereload: true
livereload: false
}
},
test: {
options: {
port: 8000,
base: 'src/javascripts/test/fixtures/examples/blog/',
keepalive: false,
livereload: false
}
}
},

json_server: {
stub: {
options: {
Expand All @@ -170,89 +47,47 @@ module.exports = function (grunt) {
}
}
},

// Watches files for changes and runs tasks based on the changed files
watch: {
configFiles: {
files: ['Gruntfile.js', 'grunt/grunt-*.json'],
tasks: ['build:dev', 'ngconfig', 'copy_build:dev'],
options: {
// reload watchers since configuration may have changed
reload: true
}
},
javascripts: {
files: ['src/javascripts/ng-admin.js', 'src/javascripts/ng-admin/**/**/*.js', 'src/javascripts/ng-admin/**/**/*.html'],
tasks: ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'copy:js_dev', 'copy:es6_dev', 'copy:es6_devmap'],
options: {
atBegin: true,
livereload: true
}
},
sass: {
files: ['src/sass/*.scss'],
tasks: ['compass:dev', 'concat:css', 'copy:fonts_dev', 'copy:assets_dev', 'copy:css_dev'],
options: {
atBegin: true,
livereload: true
}
}
},

// Test settings
karma: {
unit: {
configFile: 'src/javascripts/test/karma.conf.js',
singleRun: true
}
},

protractor: {
e2e: {
configFile: 'src/javascripts/test/protractor.conf.js',
keepAlive: true,
debug: true
}
},

mochaTest: {
test: {
options: {
require: 'mocha-traceur'
},
src: ['src/javascripts/ng-admin/es6/tests/**/*.js']
}
},
exec: {
webpack: './node_modules/webpack/bin/webpack.js',
webpack_watch: './node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --colors'
}
});

// load npm tasks
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-json-server');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-mocha-test');

// register tasks
grunt.registerTask('ngconfig', ['babel', 'requirejs:ngconfig']);
grunt.registerTask('test', ['mochaTest', 'karma', 'build', 'copy_build', 'connect', 'protractor']);
grunt.registerTask('build', ['ngconfig', 'requirejs:prod', 'ngAnnotate', 'uglify', 'compass:prod', 'cssmin:combine', 'clean:build']);
grunt.registerTask('copy_build', ['copy:config', 'copy:es6', 'copy:angular', 'copy:js_dev', 'copy:css', 'copy:fonts_dev']);
grunt.registerTask('test', ['mochaTest', 'karma', 'test:e2e']);
grunt.registerTask('test:e2e', ['test:e2e:prepare', 'json_server', 'connect:test', 'protractor']);
grunt.registerTask('test:e2e:prepare', ['exec:webpack', 'copy:test_sample_app', 'copy:test_build']);

grunt.registerTask('test:local', ['mochaTest', 'karma', 'build:dev', 'copy_build:dev', 'test:local:e2e']);
grunt.registerTask('test:local:e2e', ['json_server', 'connect', 'protractor']);
grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'compass:dev', 'concat:css']);
grunt.registerTask('copy_build:dev', ['copy:es6_dev', 'copy:es6_devmap', 'copy:js_dev', 'copy:angular', 'copy:css_dev', 'copy:fonts_dev', 'clean']);
grunt.registerTask('test:local', ['mochaTest', 'karma', 'test:local:e2e']);
grunt.registerTask('test:local:e2e', ['test:e2e:prepare', 'json_server', 'connect:test', 'protractor']);

// register default task
grunt.registerTask('default', ['copy:angular', 'json_server', 'connect', 'watch']);
grunt.registerTask('default', ['json_server', 'connect:dev', 'exec:webpack_watch']);
};
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ install:
run:
@grunt

build-dev:
@grunt build:dev
@echo "Files build/ng-admin.min.css and build/ng-admin.min.js updated (no minification)"

build:
@grunt build
@NODE_ENV=production ./node_modules/webpack/bin/webpack.js -p --progress
@cp -Rf build/* examples/blog/build/
@echo "Files build/ng-admin.min.css and build/ng-admin.min.js updated (with minification)"

test:
Expand Down
Binary file removed assets/fonts/FontAwesome.otf
Binary file not shown.
Binary file removed assets/fonts/fontawesome-webfont.eot
Binary file not shown.
Loading