Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit f158cce

Browse files
committed
Update build process.
1 parent 8be0851 commit f158cce

17 files changed

+978
-78
lines changed

Gruntfile.js

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
module.exports = function(grunt) {
22

3-
var remapify = require('remapify');
4-
3+
// -- Plugins --------------------------------------------------------------
54
// Uncomment the next line to report the Grunt execution time (for optimization, etc)
65
//require('time-grunt')(grunt);
76

87
// Intelligently lazy-loads tasks and plugins as needed at runtime.
9-
require('jit-grunt')(grunt);
8+
require('jit-grunt')(grunt)({ customTasksDir: 'tasks' });
109

11-
var shouldOpen = grunt.option('open');
10+
// -- Options --------------------------------------------------------------
11+
// All builds are considered to be development builds, unless they're not.
12+
grunt.option('dev', !grunt.option('prod'));
1213

13-
// Project configuration.
14+
// -- Configuration --------------------------------------------------------
1415
grunt.initConfig({
1516

16-
//Read the package.json
17+
// Load `package.json`so we have access to the project metadata such as name and version number.
1718
pkg: grunt.file.readJSON('package.json'),
1819

20+
// Load `build-env.js`so we have access to the project environment configuration and constants.
21+
env: require('./build-env'),
22+
1923
/**
2024
* A code block that will be added to our minified code files.
2125
* Gets the name and appVersion and other info from the above loaded 'package.json' file.
@@ -38,66 +42,26 @@ module.exports = function(grunt) {
3842
* Deletes our production folder before we create a new build.
3943
*/
4044
clean: {
41-
web: ['web']
42-
},
43-
44-
/**
45-
* Compiles the Handlebars templates into pre-compiled handlebars templates
46-
*/
47-
handlebars: {
48-
compile: {
49-
options: {
50-
amd: ['handlebars'],
51-
namespace: 'JST',
52-
// Registers all files that start with '_' as a partial.
53-
partialRegex: /^_/,
54-
// Shortens the file path for the templates.
55-
processName: function(filePath) { // input: src/templates/_header.hbs
56-
return filePath.slice(filePath.indexOf('template'), filePath.lastIndexOf('.')); // output: templates/_header
57-
},
58-
// Shortens the file path for the partials.
59-
processPartialName: function(filePath) { // input: src/templates/_header.hbs
60-
return filePath.slice(filePath.indexOf('template'), filePath.lastIndexOf('.')); // output: templates/_header
61-
}
62-
},
63-
files: {
64-
'src/assets/scripts/templates.js': 'src/assets/templates/**/*.hbs'
65-
}
66-
}
45+
before: ['web', '.tmp']
6746
},
6847

6948
/**
7049
* Copy and needed files to the web folder.
7150
*/
7251
copy: {
73-
styles: {
52+
data: {
7453
files: [{
7554
expand: true,
76-
cwd: 'src/',
77-
dest: 'web/',
55+
cwd: '<%= env.DIR_SRC %>',
56+
dest: '<%= env.DIR_DEST %>',
7857
src: [
79-
'index.html',
80-
'assets/media/**',
81-
'assets/vendor/todomvc-common/bg.png',
82-
'assets/{styles,vendor}/**/*.css',
83-
'assets/{scripts,vendor}/**/*.js'
58+
'assets/data/**/*',
59+
'assets/media/**'
8460
]
8561
}]
8662
}
8763
},
8864

89-
connect: {
90-
server: {
91-
options: {
92-
port: 31415,
93-
protocol: 'http',
94-
base: 'web/',
95-
livereload: true,
96-
open: shouldOpen ? true : false // opens a tab in your default browser e.g. grunt launch --open
97-
}
98-
}
99-
},
100-
10165
/**
10266
* Watches files and will run task(s) when files are changed. It will also reload/refresh the browser.
10367
*/
@@ -106,42 +70,48 @@ module.exports = function(grunt) {
10670
options: {
10771
livereload: true
10872
},
109-
files: ['src/**/*.html', 'src/**/*.css'],
73+
files: ['<%= env.DIR_SRC %>/**/*.html', '<%= env.DIR_SRC %>/**/*.css'],
11074
tasks: ['copy']
11175
},
11276
script: {
11377
options: {
11478
livereload: true
11579
},
116-
files: ['src/**/*.js'],
117-
tasks: ['copy']
80+
files: ['<%= env.DIR_SRC %>/**/*.js'],
81+
tasks: ['buildRequire']
11882
},
11983
templates: {
12084
options: {
12185
livereload: true
12286
},
123-
files: ['src/**/*.hbs'],
124-
tasks: ['handlebars']
87+
files: ['<%= env.DIR_SRC %>/**/*.hbs'],
88+
tasks: ['precompileJst']
12589
}
12690
}
12791
});
12892

12993
/**
13094
* Grunt tasks:
13195
*
132-
* grunt (Will build code for production)
133-
* grunt launch (Will build code for production and open the browser with the application)
96+
* grunt (Will build code for production)
97+
* grunt launch (Will build code for production and watch files)
98+
* grunt launch --open (Will build code for production and watch files then opens a tab in your default browser)
13499
*/
135100
grunt.registerTask('default', [
136-
'clean',
137-
'handlebars',
138-
'copy'
101+
'clean:before',
102+
'buildMarkup',
103+
'precompileJst',
104+
'buildStyles',
105+
'buildRequire',
106+
'copy:data'
139107
]);
140108

141-
grunt.registerTask('launch', [
109+
grunt.registerTask('launch', 'Runs build, launches http-server, watches for file changes', [
142110
'default',
143-
'connect',
111+
'connectHttp',
144112
'watch'
145113
]);
146114

115+
grunt.loadNpmTasks('grunt-contrib-watch');
116+
147117
};

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Download dependencies and build:
55
npm install
66
bower install
77

8-
grunt launch
8+
grunt launch --open

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
],
2525
"dependencies": {
2626
"requirejs": "~2.1.22",
27-
"structurejs": "~0.9.2"
27+
"structurejs": "*"
2828
}
2929
}

build-env.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict';
2+
3+
/**
4+
* Environment constants.
5+
*
6+
* This configuration file contains all of the environment-specific values
7+
* needed to build a working website.
8+
*
9+
* @class Config
10+
* @static
11+
*/
12+
var Config = {
13+
14+
/**
15+
* Path where Node.js modules are installed. No trailing slash.
16+
*
17+
* @property DIR_NPM
18+
* @type string
19+
*/
20+
DIR_NPM: 'node_modules',
21+
22+
/**
23+
* Path where Bower components are installed. No trailing slash.
24+
*
25+
* @property DIR_BOWER
26+
* @type string
27+
*/
28+
DIR_BOWER: 'src/assets/vendor',
29+
30+
/**
31+
* Path to uncompiled source files. No trailing slash.
32+
*
33+
* @property DIR_SRC
34+
* @type string
35+
*/
36+
DIR_SRC: 'src',
37+
38+
/**
39+
* Path to temporary directory (for multi-pass compilation). No trailing slash.
40+
*
41+
* @property DIR_TMP
42+
* @type string
43+
*/
44+
DIR_TMP: '.tmp',
45+
46+
/**
47+
* Path to compiled output files. No trailing slash.
48+
*
49+
* @property DIR_DEST
50+
* @type string
51+
*/
52+
DIR_DEST: 'web',
53+
54+
/**
55+
* Path to documentation output files. No trailing slash.
56+
*
57+
* @property DIR_DOCS
58+
* @type string
59+
*/
60+
DIR_DOCS: 'docs'
61+
62+
};
63+
64+
module.exports = Config;

src/assets/scripts/TestApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define(function(require, exports, module) { // jshint ignore:line
66
var Stage = require('structurejs/display/Stage');
77
var NavigationView = require('./view/NavigationView');
88
var LoginView = require('./view/LoginView');
9-
require('templates'); // jshint ignore:line
9+
require('precompiledJst'); // jshint ignore:line
1010

1111
/**
1212
* TODO: YUIDoc_comment

src/assets/scripts/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ require.config({
44

55
paths: {
66
requirejs: '../vendor/requirejs/require',
7-
jquery: '../vendor/jquery/dist/jquery',
8-
handlebars: '../vendor/handlebars/handlebars.runtime',
7+
jquery: '../vendor/jquery/dist/jquery.min',
8+
handlebars: '../vendor/handlebars/handlebars.min',
99
structurejs: '../vendor/structurejs/js'
1010
},
1111

src/index.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88

99
<!-- SEO -->
10-
<title>StructureJS Boilerplate (TypeScript)</title>
10+
<title>StructureJS Boilerplate (RequireJS)</title>
1111
<meta name="description" content="" />
1212
<meta name="author" content="" />
1313

@@ -69,15 +69,16 @@ <h1 class="hd-page"></h1>
6969
</script>
7070

7171
<!-- JAVASCRIPT -->
72-
<!-- build:js assets/scripts/vendor.js -->
73-
<script src="assets/vendor/jquery/dist/jquery.js"></script>
74-
<script src="assets/vendor/handlebars/handlebars.js"></script>
75-
<!-- endbuild -->
72+
<script src="assets/vendor/requirejs/require.js"></script>
73+
<script src="assets/scripts/config.js"></script>
74+
<script>
75+
/**
76+
* Set route and kick off RequireJs, which begins loading of scripts
77+
* starting from main.js.
78+
*/
79+
require(['main']);
80+
</script>
7681

77-
<!-- build:js assets/scripts/main.js -->
78-
<script src="assets/scripts/precompiledJst.js"></script>
79-
<script src="assets/scripts/main.js"></script>
80-
<!-- endbuild -->
8182
</body>
8283

8384
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy