-
Notifications
You must be signed in to change notification settings - Fork 4
/
Brocfile.js
101 lines (86 loc) · 2.16 KB
/
Brocfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import funnel from 'broccoli-funnel';
import merge from 'broccoli-merge-trees';
import CompileSass from 'broccoli-sass-source-maps';
import Sass from 'sass';
import Rollup from 'broccoli-rollup';
import LiveReload from 'broccoli-livereload';
import EsLint from 'broccoli-lint-eslint';
import sassLint from 'broccoli-sass-lint';
import CleanCss from 'broccoli-clean-css';
import AssetRev from 'broccoli-asset-rev';
import { log } from 'broccoli-stew';
import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
const compileSass = CompileSass(Sass);
export default (options) => {
const isProd = options.env === 'production';
const isDev = options.env === 'development';
const appRoot = 'src';
// Copy HTML file from app root to destination
const html = funnel(appRoot, {
files: ["index.html"],
annotation: "Index file",
});
let js = EsLint.create(appRoot);
const rollupPlugins = [
nodeResolve({
jsnext: true,
browser: true,
}),
commonjs({
include: 'node_modules/**',
}),
babel({
exclude: "node_modules/**",
}),
];
if (isProd) {
rollupPlugins.push(uglify());
}
// Compile JS through rollup
js = new Rollup(js, {
inputFiles: ["**/*.js"],
annotation: "JS Transformation",
rollup: {
input: "app.js",
output: {
file: "assets/js/app.js",
format: "iife",
sourcemap: isDev,
},
plugins: rollupPlugins,
}
});
// Compile scss files to css
let css = sassLint(appRoot + '/styles', {
disableTestGenerator: true,
});
css = compileSass(
[css],
'app.scss',
'assets/css/app.css',
{
annotation: "Sass files",
sourceMap: isDev,
sourceMapContents: true,
}
);
if (isProd) {
css = new CleanCss(css);
}
let tree = merge([html, js, css]);
// Include live reload server
if (isDev) {
tree = log(tree, {
output: 'tree',
});
tree = new LiveReload(tree, {
target: 'index.html',
});
} else if (isProd) {
tree = new AssetRev(tree);
}
return tree;
}