forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
executable file
·152 lines (136 loc) · 4.69 KB
/
webpack.mix.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Load required modules.
const mix = require('laravel-mix');
mix.disableNotifications();
const ESLintPlugin = require('eslint-webpack-plugin');
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
// Clean up from previous webpack runs.
del = require('del'),
del.sync('public/build/css');
del.sync('public/build/js');
del.sync('public/build/views');
del.sync('public/js/CDash_*.js');
// Determine if this is a git clone of CDash or not.
fs = require('fs');
var git_clone = false;
if (fs.existsSync('.git')) {
var git_clone = true;
// If this is a git clone, we will use the `git describe` to generate a version
// to report in the footer.
// Use current UNIX timestamp for cache busting.
version = new Date().getTime().toString();
} else {
// Otherwise if this is a release download, use the version from package.json.
var config = require('./package.json');
version = config.version;
fs.writeFileSync('./public/VERSION', 'v' + version);
}
// Write out version file for angular.js
var dir = 'public/build/js';
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(dir + '/version.js', "angular.module('CDash').constant('VERSION', '" + version + "');");
// Webpack plugins.
var webpack_plugins = [
// Replace version string in angular files.
new ReplaceInFileWebpackPlugin([
{
dir: 'public/build/views',
test: /\.html$/,
rules: [{
search: /@@version/g,
replace: version
}]
},
{
dir: 'public/js',
test: /\.js$/,
rules: [{
search: /@@cdash_version/g,
replace: version
}]
},
]),
// Linter for Vuejs files.
new ESLintPlugin({
exclude: ['node_modules', 'vendor'],
extensions: 'vue',
fix: true,
}),
];
if (git_clone) {
const GitRevisionPlugin = require('git-revision-webpack-plugin')
webpack_plugins.push(new GitRevisionPlugin());
}
// Copy angularjs files to build directory.
mix.copy('public/views/*.html', 'public/build/views/');
// Cache busting for angularjs partials.
var glob = require("glob");
glob.sync('public/views/partials/*.html').forEach(function(src) {
var dest = src.replace('.html', '_' + version + '.html');
var dest = dest.replace('views', 'build/views');
mix.copy(src, dest);
});
// Version CSS files.
mix.copy('public/css/cdash.css', 'public/build/css/cdash_' + version + '.css');
mix.copy('public/css/colorblind.css', 'public/build/css/colorblind_' + version + '.css');
mix.copy('public/css/common.css', 'public/build/css/common.css');
mix.styles([
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/bootstrap-vue/dist/bootstrap-vue.css'
], 'public/build/css/3rdparty.css').version();
// Concatenate and minify 3rd party javascript.
mix.scripts([
'public/js/jquery-1.10.2.js',
'public/js/jquery-ui-1.10.4.min.js',
'public/js/jquery.cookie.js',
'public/js/jquery.flot.min.js',
'public/js/jquery.flot.navigate.min.js',
'public/js/jquery.flot.selection.min.js',
'public/js/jquery.flot.symbol.min.js',
'public/js/jquery.flot.time.min.js',
'public/js/jquery.qtip.min.js',
'public/js/jqModal.js',
'public/js/bootstrap.min.js',
'public/js/tooltip.js',
'public/js/je_compare.js',
'node_modules/angular/angular.js',
'node_modules/angular-animate/angular-animate.js',
'node_modules/angular-clipboard/angular-clipboard.js',
'node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js',
'node_modules/angular-ui-sortable/dist/sortable.js',
'node_modules/ansi_up/ansi_up.js',
'node_modules/as-jqplot/dist/jquery.jqplot.js',
'node_modules/as-jqplot/dist/plugins/jqplot.dateAxisRenderer.js',
'node_modules/as-jqplot/dist/plugins/jqplot.highlighter.js',
'node_modules/d3/d3.js',
'node_modules/ng-file-upload/dist/ng-file-upload.js',
'node_modules/nvd3/build/nv.d3.js',
'public/js/ui-bootstrap-tpls-0.14.2.min.js'
], 'public/js/3rdparty.min.js');
// Concatenate and minify 1st party javascript.
mix.scripts([
'public/js/cdashSortable.js',
'public/js/tabNavigation.js',
'public/js/linechart.js',
'public/js/bulletchart.js',
'public/js/cdash_angular.js',
'public/build/js/version.js',
'public/js/directives/**.js',
'public/js/filters/**.js',
'public/js/services/**.js',
'public/js/controllers/**.js'
], 'public/js/1stparty.min.js');
// Combine 1st and 3rd party into a single file.
mix.scripts([
'public/js/3rdparty.min.js',
'public/js/1stparty.min.js',
], 'public/js/CDash_' + version + '.min.js');
// Boilerplate.
mix.js('resources/js/app.js', 'public/laravel/js').vue().version();
mix.sass('resources/sass/app.scss', 'public/laravel/css').version();
// Added this line to get mocha testing working with versioning.
mix.copy('resources/js/app.js', 'public/main.js');
mix.webpackConfig({
plugins: webpack_plugins
});