Skip to content

Commit

Permalink
Lots of build changes and production JS build
Browse files Browse the repository at this point in the history
  • Loading branch information
ediblecode committed Sep 15, 2016
1 parent aca29f3 commit a27ce40
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .grunt-tasks/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
dev: {
NODE_ENV : "development"
},
dist: {
NODE_ENV : "production"
}
};
1 change: 1 addition & 0 deletions .grunt-tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
"./src/javascripts/**/*.js",
"./Gruntfile.js",
"./webpack.config.js",
"./webpack.production.config.js",
"./.grunt-tasks/**/*.js",
"./web/server/**/*.js",
"./web/client/**/*.js"
Expand Down
24 changes: 6 additions & 18 deletions .grunt-tasks/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@ module.exports = {
options: {
stream: true
},
watch: {
tasks: [{
grunt: true,
args: ["watch:sass"]
}, {
grunt: true,
args: ["watch:eslint"]
}, {
grunt: true,
args: ["watch:jsbuild"]
}, {
grunt: true,
args: ["watch:express"]
}, {
grunt: true,
args: ["watch:public"]
}]
},
default: {
options: {
grunt: true
},
tasks: ["sassdoc", "documentation", "modernizr", "sass:dev", "webpack:dev"]
}
};
4 changes: 2 additions & 2 deletions .grunt-tasks/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
outputStyle: "compressed"
},
files: {
"./dist/stylesheets/main.css": "./web/client/stylesheets/main.scss"
"./dist/stylesheets/app.css": "./web/client/stylesheets/app.scss"
}
},
dev: {
Expand All @@ -34,7 +34,7 @@ module.exports = {
includePaths: ["./src/stylesheets"]
},
files: {
"./dist/stylesheets/main.css": "./web/client/stylesheets/main.scss"
"./dist/stylesheets/app.css": "./web/client/stylesheets/app.scss"
}
}
};
2 changes: 1 addition & 1 deletion .grunt-tasks/sasslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
src: ["./src/stylesheets/**/*.scss", "./web/client/stylesheets/**/*.scss"]
},
options: {
configFile: "./src/stylesheets/.sass-lint.yml",
configFile: "./src/stylesheets/.sass-lint.yml"
}
};
2 changes: 1 addition & 1 deletion .grunt-tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
},
jsbuild: {
files: ["./src/javascripts/**/*.js", "./web/client/javascripts/**/*.js"],
tasks: ["webpack"],
tasks: ["webpack:dev"],
options: {
// Speed up watch task:
spawn: false
Expand Down
4 changes: 3 additions & 1 deletion .grunt-tasks/webpack.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
default: require("./../webpack.config.js")
dev: require("./../webpack.config.js"),

dist: require("./../webpack.production.config.js")
};
13 changes: 5 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ module.exports = function(grunt) {
// Generate documentation form comments in SASS and JS
r("docs", ["sassdoc", "documentation"]);

// Build in dev mode
r("build", ["modernizr", "sass:dev", "webpack"]);

// Serve the app and watch for changes
r("serve", ["express"/*, "open"*/, "parallel:watch"]);
// Serve the app and open in a browser
r("serve", ["express", "open"]);

// For deploying the web app. Builds minified SASS/JS
r("dist", ["clean", "sass:dist", "webpack"]);
r("dist", ["env:dist", "clean", "sass:dist", "webpack:dist"]);

// For building before publishing to NPM etc
r("publish", ["clean", "sass:publish", "sass:publishMin", "webpack"]);
r("publish", ["env:dist", "clean", "sass:publish", "sass:publishMin", "webpack:dist"]);

r("default", ["lint", "docs", "build", "serve"]);
r("default", ["lint", "parallel:default", "watch"]);
};
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ Before you run any tasks, you'll have to run the following from the command line

| Task | Description |
| ---- | ----------- |
| `grunt` | Default. Lints, builds everything and runs an express server and a watch task for dev changes. |
| `grunt build` | Builds a custom modernizr package, CSS and JS. Usually not used directly. |
| `grunt serve` | Runs an express app and watches for changes |
| `grunt` | Default. Lints, builds everything in parallel and runs an express server and a watch task for dev changes. |
| `grunt lint` | Lints SASS (sasslint) and JS (eslint) |
| `grunt docs` | Generates documentation JSON files for SASS and JS |
| `grunt dist` | Builds documentation, modernizr, CSS and JS in production mode (minified etc). |
| `grunt dist` | Builds documentation, modernizr, CSS and JS in production mode (minified etc). Fro deploying the web app itself. |
| `grunt publish` | Builds minified code for publishing to NPM etc |

#### NPM

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"main": "web/server/index.js",
"scripts": {
"start": "grunt",
"build:webpack": "webpack -d --progress --colors",
"dist:webpack": "NODE_ENV=production webpack -p",
"webpack:dev": "SET \"NODE_ENV=development\" && webpack --progress --colors --display-error-details",
"webpack:dist": "SET \"NODE_ENV=production\" && webpack --config ./webpack.production.config.js",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "grunt lint",
"serve": "set PORT=54321&& node web/server",
Expand All @@ -33,7 +33,7 @@
"devDependencies": {
"grunt-contrib-watch": "^1.0.0",
"grunt-express-server": "^0.5.3",
"grunt-open": "^0.2.3"
"grunt-open": "^0.2.3",
"webpack-dev-server": "^1.15.2",
"webpack-notifier": "^1.4.1"
},
Expand All @@ -59,6 +59,7 @@
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-documentation": "^1.2.0",
"grunt-env": "^0.4.4",
"grunt-eslint": "^19.0.0",
"grunt-jsdoc": "^2.1.0",
"grunt-modernizr": "^1.0.2",
Expand All @@ -79,7 +80,7 @@
"nunjucks": "^2.5.2",
"sassdoc-extras": "^2.4.1",
"serve-favicon": "^2.3.0",
"webpack": "^1.13.1",
"webpack": "^1.13.2"
},
"engines": {
"node": ">=4"
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# See http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories

dist/*
!.grunt-tasks/*
!.grunt-tasks*
5 changes: 5 additions & 0 deletions src/javascripts/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"es6": true,
"commonjs": true
},
"globals": {
"process": false,
"$": false,
"PRODUCTION": false
},
"extends": "eslint:recommended",
"parser": "babel-eslint",
"plugins": [
Expand Down
12 changes: 12 additions & 0 deletions src/javascripts/experience.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import $ from "jquery";
import pluginAutoLoader from "plugin-autoloader";

$().ready(function() {

// Load any plugins automatically
pluginAutoLoader.findPlugins();
});

export default {
test: true
};
File renamed without changes.
6 changes: 4 additions & 2 deletions web/client/stylesheets/components/_swatch.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.swatch {
border-radius: 0 999px 999px 999px;
border-radius: 0 999px 999px;
display: none;
float: left;
height: 100px;
Expand All @@ -12,7 +12,9 @@
@each $name, $palette in $palettes {

@each $key, $hex in $palette {
&--#{$name}-#{$key} {
$selector: '#{$name}-#{$key}';

&--#{$selector} {
background: $hex;
display: block;

Expand Down
4 changes: 2 additions & 2 deletions web/server/views/layouts/_layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="/javascripts/modernizr-custom.js"></script>

<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="/stylesheets/main.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="/stylesheets/app.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/default.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/github.min.css">
<link href="//fonts.googleapis.com/css?family=Lato:200normal,200italic,300normal,300italic,400normal,400italic,700normal,700italic,900normal,900italic" rel="stylesheet" type="text/css">
Expand Down Expand Up @@ -106,7 +106,7 @@
</footer>

<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js" integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8=" crossorigin="anonymous"></script>
<script src="/javascripts/app.bundle.js"></script>
<script src="/javascripts/app.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/scss.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
Expand Down
51 changes: 24 additions & 27 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,39 @@
var WebpackNotifierPlugin = require("webpack-notifier");
var webpack = require("webpack");

var isProduction = (process.env.NODE_ENV === "production");

var plugins = [
// Notify on success/error
new WebpackNotifierPlugin({title: "NICE Bootstrap build"}),

// Magic globals for environment gating e.g. if (__PRODUCTION__) { }
new WebpackNotifierPlugin({title: "NICE Experience"}),
new webpack.DefinePlugin({
PRODUCTION: false
}),
new webpack.DefinePlugin({
PRODUCTION: isProduction
"process.env": {
NODE_ENV: JSON.stringify("development")
}
}),
new webpack.ProvidePlugin({
$: "jquery"
}),
new webpack.optimize.UglifyJsPlugin({
minimize: false,
mangle: false,
compress: false,
output: {
beautify: true
}
})
];

if(isProduction) {
plugins.push(
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
);
}

module.exports = [{
name: "js",
module.exports = {
name: "app",
entry: [/*"babel-polyfill", */"./web/client/javascripts/app"],
output: {
path: "./dist/javascripts",
filename: "app.bundle.js",
sourceMapFilename: "app.bundle.map"
filename: "app.js",
sourceMapFilename: "app.map"
},
module: {
/*preLoaders: [{
test: /\.js$/,
loader: "eslint",
exclude: /(node_modules|bower_components)/
}],*/
loaders: [{
test: /\.js$/,
loaders: ["babel-loader"],
Expand All @@ -48,12 +45,12 @@ module.exports = [{
},
externals: { jquery: "jQuery" },
resolve: {
root: ["./web/client/javascripts/", "./src/javascripts/"]
modulesDirectories: ["./web/client/javascripts/", "./src/javascripts/"]
},
devtool: "#source-map",
plugins: plugins,
eslint: {
ignorePath: "./src/javascripts/.eslintignore",
configFile: "./src/javascripts/.eslintrc.json"
}
}];
};
55 changes: 55 additions & 0 deletions webpack.production.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// <binding ProjectOpened="Watch - Development" />
/*eslint-env node*/

var webpack = require("webpack");

var appConfig = require("./webpack.config.js");

var prodPlugins = [
new webpack.optimize.OccurrenceOrderPlugin(true),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
},
mangle: {
except: ["$super", "$", "exports", "require"]
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.DefinePlugin({
PRODUCTION: true
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new webpack.ProvidePlugin({
$: "jquery"
})
];

appConfig.plugins = prodPlugins;

module.exports = [
appConfig,
{
name: "experience",
entry: ["./src/javascripts/experience"],
output: {
path: "./dist/javascripts",
filename: "experience.min.js",
sourceMapFilename: "experience.min.map"
},
module: appConfig.module,
resolve: {
modulesDirectories: ["./src/javascripts/"]
},
externals: appConfig.externals,
devtool: "#cheap-module-source-map",
eslint: appConfig.eslint,
plugins: prodPlugins
}
];

0 comments on commit a27ce40

Please sign in to comment.