-
Notifications
You must be signed in to change notification settings - Fork 33
/
webpack.config.js
171 lines (166 loc) 路 5.52 KB
/
webpack.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
const path = require('path');
const webpack = require('webpack');
const MoveFilePlugin = require('./plugins/MoveFilePlugin');
// First check if we can load Comunica form cwd, if not, fallback to the default
let pathToComunica;
let comunicaOverride;
try {
pathToComunica = require.resolve('@comunica/query-sparql', { paths: [process.cwd()] });
comunicaOverride = true;
}
catch {
pathToComunica = require.resolve('@comunica/query-sparql', { paths: [__dirname] });
comunicaOverride = false;
}
// Make this an object, so we can mutate it from the top level of the config
// and have the options propagated to the plugins
const baseURL = {
search: '<%= baseURL %>',
// Default to the localhost for dev mode. The generate.js script should replace this
// value in production mode.
replace: 'http://localhost:8080/',
flags: 'g'
}
// Make this an object, so we can mutate it from the top level of the config
// and have the options propagated to the plugins
const buildContext = {
dir: 'build',
}
module.exports = [
{
entry: [
path.join(__dirname, './deps/jquery-2.1.0.js'),
path.join(__dirname, './deps/chosen-1.1.0.js'),
path.join(__dirname, './deps/fast-scroller.js'),
path.join(__dirname, './src/ldf-client-ui.js'),
path.join(__dirname, './src/ldf-client-url-state.js'),
path.join(__dirname, './index.html'),
path.join(__dirname, './styles/ldf-client.css'),
path.join(__dirname, './images/chosen-sprite.png'),
path.join(__dirname, './images/chosen-sprite@2x.png'),
path.join(__dirname, './images/graphql.svg'),
path.join(__dirname, './images/logo.svg'),
path.join(__dirname, './images/settings.svg'),
path.join(__dirname, './images/sparql.png'),
path.join(__dirname, './favicon.ico'),
path.join(__dirname, './solid-client-id.jsonld'),
],
output: {
filename: 'scripts/ldf-client-ui.min.js',
path: path.join(__dirname, '/build'),
libraryTarget: 'window',
},
plugins: [
new webpack.ProvidePlugin({
jQuery: path.join(__dirname, '/deps/jquery-2.1.0.js'),
}),
new webpack.NormalModuleReplacementPlugin(/^comunica-packagejson$/, (process.platform === 'win32' ? '' : '!!json-loader!') + path.join(pathToComunica, '../../package.json')),
// Include the generated queries.json file by moving it from the current working directory (where it was generated) to the build path.
new MoveFilePlugin(
() => path.join(process.cwd(), 'queries.json'),
() => path.join(__dirname, `${buildContext.dir}/queries.json`)
),
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
type: 'javascript/auto',
test: /query-sparql\/package\.json$/,
use: [
{ loader: 'file-loader', options: { name: 'scripts/[name].[ext]' } },
],
},
{
type: 'javascript/auto',
test: /\.html$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: '[name].[ext]' } },
],
},
{
type: 'javascript/auto',
test: /queries\.json$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: '[name].[ext]' } },
],
},
{
type: 'javascript/auto',
test: /solid-client-id\.jsonld$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: '[name].[ext]' } },
],
},
{
type: 'javascript/auto',
test: /((solid-client-id\.jsonld)|(\.js))$/,
use: [
{
loader: require.resolve('string-replace-loader'),
options: baseURL
},
],
},
{
test: /\.(jpg|png|gif|svg|ico)$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: 'images/[name].[ext]' } },
],
},
{
test: /\.css$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: 'styles/[name].[ext]' } },
],
},
{ test: /images\/*\.svg$/, use: require.resolve('file-loader') },
{
test: /leaflet.*\.png$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: 'styles/images/[name].[ext]' } },
],
},
],
},
},
{
entry: [
path.join(__dirname, './src/ldf-client-worker.js'),
],
output: {
filename: 'scripts/ldf-client-worker.min.js',
path: path.join(__dirname, '/build'),
libraryTarget: 'this', // Fixes hot loading of web worker not working in Webpack
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.NormalModuleReplacementPlugin(/^my-comunica-engine$/, path.join(process.cwd(), '.tmp-comunica-engine.js')),
...comunicaOverride ? [] : [
new webpack.NormalModuleReplacementPlugin(/^\@comunica/, (resource) => {
resource.context = __dirname;
}),
],
],
resolveLoader: {
modules: ['node_modules', path.resolve(__dirname, 'node_modules')],
},
},
];
// Export the baseURL and buildContext objects, so we can mutate it in the generate script
module.exports.baseURL = baseURL;
module.exports.buildContext = buildContext;