-
Notifications
You must be signed in to change notification settings - Fork 332
/
webpack.common.config.js
225 lines (214 loc) · 10.2 KB
/
webpack.common.config.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var SaveAssetsJson = require('assets-webpack-plugin');
var addons = require('./addons.json');
var root = path.resolve(__dirname, 'website', 'static');
/** Return the absolute path given a path relative to ./website/static */
var staticPath = function(dir) {
return path.resolve(root, dir);
};
var nodePath = function(dir) {
return path.resolve(__dirname, 'node_modules', dir);
};
var addonsPath = function(dir) {
return path.resolve(__dirname, 'addons', dir);
};
/**
* Each JS module for a page on the OSF is webpack entry point. These are built
* to website/static/public/
*/
var entry = {
// JS
'base-page': staticPath('js/pages/base-page.js'),
'dashboard-page': staticPath('js/pages/dashboard-page.js'),
'profile-page': staticPath('js/pages/profile-page.js'),
'project-dashboard': staticPath('js/pages/project-dashboard-page.js'),
'project-base-page': staticPath('js/pages/project-base-page.js'),
'project-settings-page': staticPath('js/pages/project-settings-page.js'),
'project-addons-page': staticPath('js/pages/project-addons-page.js'),
'registration-retraction-page': staticPath('js/pages/registration-retraction-page.js'),
'registration-edit-page': staticPath('js/pages/registration-edit-page.js'),
'register-page': staticPath('js/pages/register-page.js'),
'wiki-edit-page': staticPath('js/pages/wiki-edit-page.js'),
'request-access-page': staticPath('js/pages/request-access-page.js'),
'file-page': staticPath('js/pages/file-page.js'),
'files-page': staticPath('js/pages/files-page.js'),
'reg-landing-page': staticPath('js/pages/reg-landing-page.js'),
'profile-settings-page': staticPath('js/pages/profile-settings-page.js'),
'profile-account-settings-page': staticPath('js/pages/profile-account-settings-page.js'),
'profile-settings-applications-list-page': staticPath('js/pages/profile-settings-applications-list-page.js'),
'profile-settings-applications-detail-page': staticPath('js/pages/profile-settings-applications-detail-page.js'),
'profile-settings-personal-tokens-list-page': staticPath('js/pages/profile-settings-personal-tokens-list-page.js'),
'profile-settings-personal-tokens-detail-page': staticPath('js/pages/profile-settings-personal-tokens-detail-page.js'),
'sharing-page': staticPath('js/pages/sharing-page.js'),
'conference-page': staticPath('js/pages/conference-page.js'),
'meetings-page': staticPath('js/pages/meetings-page.js'),
'view-file-tree-page': staticPath('js/pages/view-file-tree-page.js'),
'search-page': staticPath('js/pages/search-page.js'),
'profile-settings-addons-page': staticPath('js/pages/profile-settings-addons-page.js'),
'forgotpassword-page': staticPath('js/pages/forgotpassword-page.js'),
'resetpassword-page': staticPath('js/pages/resetpassword-page.js'),
'claimaccount-page': staticPath('js/pages/claimaccount-page.js'),
'login-page': staticPath('js/pages/login-page.js'),
'notifications-config-page': staticPath('js/pages/notifications-config-page.js'),
'render-nodes': staticPath('js/pages/render-nodes.js'),
'institution-page': staticPath('js/pages/institution-page.js'),
// Commons chunk
'vendor': [
// Vendor libraries
'knockout',
'knockout.validation',
'moment',
'bootstrap',
'bootbox',
'bootstrap-editable',
'select2',
'dropzone',
'knockout-sortable',
'loaders.css',
'treebeard',
'lodash.get',
'js-cookie',
'URIjs',
// Common internal modules
'js/fangorn',
'js/citations',
'js/osfHelpers',
'js/osfToggleHeight',
'mithril',
// Main CSS files that get loaded above the fold
nodePath('select2/select2.css'),
nodePath('bootstrap/dist/css/bootstrap.css'),
'@centerforopenscience/osf-style',
staticPath('css/style.css'),
],
};
// Collect log text from addons
var mainLogs = require(staticPath('js/logActionsList.json'));
var anonymousLogs = require(staticPath('js/anonymousLogActionsList.json'));
var addonLog;
var anonymousAddonLog;
// Collect addons endpoints. If an addon's static folder has
// any of the following files, it will be added as an entry point
// and output to website/static/public/js/<addon-name>/files.js
var addonModules = ['files.js', 'node-cfg.js', 'user-cfg.js', 'file-detail.js', 'widget-cfg.js'];
addons.addons.forEach(function(addonName) {
var baseDir = addonName + '/';
addonModules.forEach(function(module) {
var modulePath = path.resolve(__dirname, 'addons',
addonName, 'static', module);
if (fs.existsSync(modulePath)) {
var entryPoint = baseDir + module.split('.')[0];
entry[entryPoint] = modulePath;
}
});
var logTextPath = path.resolve(__dirname, 'addons',
addonName, 'static', addonName + 'LogActionList.json');
if(fs.existsSync(logTextPath)){
addonLog = require(logTextPath);
for (var attrname in addonLog) { mainLogs[attrname] = addonLog[attrname]; }
}
var anonymousLogTextPath = path.resolve(__dirname, 'addons',
addonName, 'static', addonName + 'AnonymousLogActionList.json');
if(fs.existsSync(anonymousLogTextPath)) {
anonymousAddonLog = require(anonymousLogTextPath);
for (var log in anonymousAddonLog) { anonymousLogs[log] = anonymousAddonLog[log]; }
}
});
fs.writeFileSync(staticPath('js/_allLogTexts.json'), JSON.stringify(mainLogs));
fs.writeFileSync(staticPath('js/_anonymousLogTexts.json'), JSON.stringify(anonymousLogs));
var resolve = {
modules: [
root,
'./website/static/vendor/bower_components',
'node_modules',
],
extensions: ['*', '.es6.js', '.js', '.min.js'],
// Need to alias libraries that aren't managed by bower or npm
alias: {
'knockout-sortable': staticPath('vendor/knockout-sortable/knockout-sortable.js'),
'bootstrap-editable': staticPath('vendor/bootstrap-editable-custom/js/bootstrap-editable.js'),
'jquery-blockui': staticPath('vendor/jquery-blockui/jquery.blockui.js'),
'bootstrap': nodePath('bootstrap/dist/js/bootstrap.js'),
'Caret.js': staticPath('vendor/bower_components/Caret.js/dist/jquery.caret.min.js'),
'osf-panel': staticPath('vendor/bower_components/osf-panel/dist/jquery-osfPanel.min.js'),
'jquery-qrcode': staticPath('vendor/bower_components/jquery-qrcode/jquery.qrcode.min.js'),
'jquery-tagsinput': staticPath('vendor/bower_components/jquery.tagsinput/jquery.tagsinput.js'),
'clipboard': staticPath('vendor/bower_components/clipboard/dist/clipboard.js'),
// Needed for knockout-sortable
'jquery.ui.sortable': staticPath('vendor/bower_components/jquery-ui/ui/widgets/sortable.js'),
'truncate': staticPath('vendor/bower_components/truncate/jquery.truncate.js'),
// Needed for ace code editor in wiki
'ace-noconflict': staticPath('vendor/bower_components/ace-builds/src-noconflict/ace.js'),
'ace-ext-language_tools': staticPath('vendor/bower_components/ace-builds/src-noconflict/ext-language_tools.js'),
'ace-mode-markdown': staticPath('vendor/bower_components/ace-builds/src-noconflict/mode-markdown.js'),
'pagedown-ace-converter': addonsPath('wiki/static/pagedown-ace/Markdown.Converter.js'),
'pagedown-ace-sanitizer': addonsPath('wiki/static/pagedown-ace/Markdown.Sanitizer.js'),
'pagedown-ace-editor': addonsPath('wiki/static/pagedown-ace/Markdown.Editor.js'),
'wikiPage': addonsPath('wiki/static/wikiPage.js'),
'typo': staticPath('vendor/ace-plugins/typo.js'),
'highlight-css': nodePath('highlight.js/styles/default.css'),
'pikaday-css': nodePath('pikaday/css/pikaday.css'),
// Also alias some internal libraries for easy access
'addons': path.resolve(__dirname, 'addons'),
'tests': staticPath('js/tests'),
// GASP Items not defined as main in its package.json
'TweenLite' : nodePath('gsap/src/minified/TweenLite.min.js'),
'EasePack' : nodePath('gsap/src/minified/easing/EasePack.min.js'),
}
};
var externals = {
// require("jquery") is external and available
// on the global var jQuery, which is loaded with CDN
'jquery': 'jQuery',
'jquery-ui': 'jQuery.ui',
'raven-js': 'Raven',
'MathJax': 'MathJax'
};
var plugins = [
// Bundle common code between modules
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js' }),
// Make jQuery available in all modules without having to do require('jquery')
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
// Slight hack to make sure that CommonJS is always used
new webpack.DefinePlugin({
'define.amd': false,
'__ENABLE_DEV_MODE_CONTROLS': fs.existsSync(staticPath(path.join('built', 'git_logs.json')))
}),
];
var output = {
path: path.resolve(__dirname, 'website', 'static', 'public', 'js'),
// publicPath: '/static/', // used to generate urls to e.g. images
filename: '[name].js',
sourcePrefix: ''
};
module.exports = {
entry: entry,
resolve: resolve,
devtool: 'source-map',
externals: externals,
plugins: plugins,
output: output,
module: {
rules: [
{test: /\.es6\.js$/, exclude: [/node_modules/, /bower_components/, /vendor/], loader: 'babel-loader'},
{test: /\.css$/, use: [{loader: 'style-loader'}, {loader: 'css-loader'}]},
// url-loader uses DataUrls; files-loader emits files
{test: /\.png$/, loader: 'url-loader?limit=100000&mimetype=image/png'},
{test: /\.gif$/, loader: 'url-loader?limit=10000&mimetype=image/gif'},
{test: /\.jpg$/, loader: 'url-loader?limit=10000&mimetype=image/jpg'},
{test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?mimetype=application/font-woff'},
{test: /\.svg/, loader: 'file-loader'},
{test: /\.eot/, loader: 'file-loader'},
{test: /\.ttf/, loader: 'file-loader'},
{ parser: { amd: false }}
]
},
node: {
fs: 'empty'
}
};