-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathwebpack.config.js
More file actions
151 lines (140 loc) · 4 KB
/
Copy pathwebpack.config.js
File metadata and controls
151 lines (140 loc) · 4 KB
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
/* eslint-env node */
require('babel-polyfill')
const DojoWebpackPlugin = require('./dojo-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
// if JBROWSE_BUILD_MIN env var is 1 or true, then we also minimize the JS
// and forego generating source maps
const DEBUG = ![1, '1', 'true'].includes(process.env.JBROWSE_BUILD_MIN)
var webpackConf = {
entry: {
main: 'src/JBrowse/main',
browser: 'src/JBrowse/standalone',
},
plugins: [
new CleanWebpackPlugin(['dist']),
new DojoWebpackPlugin({
loaderConfig: require('./build/dojo-loader-config'),
environment: {
dojoRoot: process.env.JBROWSE_PUBLIC_PATH || './dist/',
},
buildEnvironment: {
dojoRoot: 'node_modules/',
},
locales: ['en'],
loader: path.resolve('./build/dojo-webpack-plugin-loader/dojo/dojo.js'),
}),
new CopyWebpackPlugin([
{
context: 'node_modules',
from: 'dojo/resources/blank.gif',
to: 'dojo/resources',
},
]),
new webpack.NormalModuleReplacementPlugin(
/^dojox\/gfx\/renderer!/,
'dojox/gfx/canvas',
),
new webpack.NormalModuleReplacementPlugin(/^dojo\/text!/, function (data) {
data.request = data.request.replace(/^dojo\/text!/, '!!raw-loader!')
}),
new webpack.NormalModuleReplacementPlugin(/^css!/, function (data) {
data.request = data.request.replace(/^css!/, '!style-loader!css-loader!')
}),
],
module: {
rules: [
{
test: /\.html$/i,
use: 'raw-loader',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.js$/,
exclude:
/node_modules\/(?!(quick-lru|@gmod\/indexedfasta|@gmod\/tabix|@gmod\/tribble-index|@gmod\/bgzf-filehandle))/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015-without-strict'],
plugins: [
'transform-async-to-generator',
'transform-es2015-classes',
],
cacheDirectory: true,
},
},
},
{
test: /src\/JBrowse\/main.js|src\/JBrowse\/standalone.js|tests\/js_tests\/main.js/,
use: [
{
loader: path.resolve('build/glob-loader.js'),
},
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
use: 'url-loader?limit=10000',
},
{
// regex replace all JBrowse plugin JS to just remove any use of
// dojo/domReady!
test: filepath =>
filepath.indexOf(__dirname + '/plugins') === 0 &&
/\.js$/.test(filepath),
use: {
loader: 'regexp-replace-loader',
options: {
match: {
pattern: '["`\']dojo/domReady!?["\'`]\s*',
flags: 'g',
},
replaceWith: '"JBrowse/has"',
},
},
},
],
},
output: {
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: process.env.JBROWSE_PUBLIC_PATH || 'dist/',
},
resolveLoader: {
modules: ['node_modules'],
},
resolve: {
symlinks: false,
},
}
if (DEBUG) {
webpackConf.mode = 'development'
webpackConf.entry.run_jasmine = 'tests/js_tests/main.js'
webpackConf.plugins.push(new webpack.optimize.AggressiveMergingPlugin())
webpackConf.devServer = {
port: 8082,
contentBase: __dirname,
publicPath: '/dist/',
before(app) {
app.use((req, res, next) => {
if (/\.(txt|json|g)z$/.test(req.url) && !req.headers.range) {
res.setHeader('Content-Encoding', 'gzip')
}
next()
})
},
}
} else {
webpackConf.mode = 'production'
webpackConf.plugins.push(new UglifyJsPlugin())
}
module.exports = webpackConf