forked from learningequality/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
134 lines (121 loc) · 4.38 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
/* eslint-env node */
const path = require('path');
const process = require('process');
const baseConfig = require('kolibri-tools/lib/webpack.config.base');
const { merge } = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const BundleTracker = require('kolibri-tools/lib/webpackBundleTracker');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const WebpackRTLPlugin = require('kolibri-tools/lib/webpackRtlPlugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const webpack = require('webpack');
const djangoProjectDir = path.resolve('contentcuration');
const staticFilesDir = path.resolve(djangoProjectDir, 'contentcuration', 'static');
const srcDir = path.resolve(djangoProjectDir, 'contentcuration', 'frontend');
const bundleOutputDir = path.resolve(staticFilesDir, 'studio');
module.exports = (env = {}) => {
const dev = env.dev;
const hot = env.hot;
const base = baseConfig({ mode: dev ? 'development' : 'production', hot, cache: dev });
if (String(base.module.rules[2].test) !== String(/\.css$/)) {
throw Error('Check base webpack configuration for update of location of css loader');
}
const rootDir = __dirname;
const rootNodeModules = path.join(rootDir, 'node_modules');
const baseCssLoaders = base.module.rules[2].use;
return merge(base, {
context: srcDir,
entry: {
// Use arrays for every entry to allow for hot reloading.
channel_edit: ['./channelEdit/index.js'],
channel_list: ['./channelList/index.js'],
settings: ['./settings/index.js'],
accounts: ['./accounts/index.js'],
administration: ['./administration/index.js'],
// A simple code sandbox to play with components in
pdfJSWorker: ['pdfjs-dist/build/pdf.worker.entry.js'],
// Utility for taking screenshots inside an iframe sandbox
htmlScreenshot: ['./shared/utils/htmlScreenshot.js'],
},
output: {
filename: dev ? '[name].js' : '[name]-[fullhash].js',
chunkFilename: dev ? '[name]-[id].js' : '[name]-[id]-[fullhash].js',
path: bundleOutputDir,
publicPath: dev ? 'http://127.0.0.1:4000/dist/' : '/static/studio/',
pathinfo: !dev,
},
devServer: {
port: 4000,
headers: {
'Access-Control-Allow-Origin': '*',
},
},
module: {
rules: [
{
test: /\.styl(us)?$/,
use: baseCssLoaders.concat('stylus-loader'),
},
{
test: /\.less?$/,
use: baseCssLoaders.concat('less-loader'),
},
],
},
resolve: {
alias: {
// explicit alias definitions (rather than modules) for speed
shared: path.resolve(srcDir, 'shared'),
frontend: srcDir,
// needed to reference Vuetify styles in the shadow DOM
vuetify: path.resolve('node_modules', 'vuetify'),
static: staticFilesDir,
},
extensions: ['.js', '.vue', '.css', '.less'],
modules: [rootNodeModules],
},
resolveLoader: {
modules: [rootNodeModules],
},
plugins: [
new webpack.IgnorePlugin({
resourceRegExp: /vuetify\/src\/stylus\//,
}),
new BundleTracker({
filename: path.resolve(djangoProjectDir, 'build', 'webpack-stats.json'),
}),
new MiniCssExtractPlugin({
filename: dev ? '[name].css' :'[name]-[fullhash].css',
chunkFilename: dev ? '[name]-[id].css' :'[name]-[fullhash]-[id].css',
}),
new WebpackRTLPlugin({
minify: false,
}),
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// include specific files based on a RegExp
include: /frontend/,
// add errors to webpack instead of warnings
failOnError: false,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd(),
}),
// This must be added in dev mode if you want to do dev work
// on the service worker.
].concat(
dev
? []
: [
new InjectManifest({
swSrc: path.resolve(srcDir, 'serviceWorker/index.js'),
swDest: 'serviceWorker.js',
}),
]
),
stats: 'normal',
});
};