-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
87 lines (83 loc) · 2.87 KB
/
webpack.common.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
/* eslint-env node */
// TODO: Sort out process for deploying built assets
// Sample dev/prod core webpack config, based on:
// https://webpack.js.org/guides/production/
// https://owais.lone.pw/blog/webpack-plus-reactjs-and-django/
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const assetPath = path.resolve(__dirname, 'assets/js');
module.exports = {
context: __dirname,
entry: {
// List of individual per-page JS files to be included
home_search: path.resolve(assetPath, 'pages/home_search.js'),
profile: path.resolve(assetPath, 'pages/profile.js'),
gwas_upload: path.resolve(assetPath, 'pages/gwas_upload.js'),
gwas_summary: path.resolve(assetPath, 'pages/gwas_summary.js'),
gwas_region: path.resolve(assetPath, 'pages/gwas_region.js'),
},
plugins: [
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
// new BundleAnalyzerPlugin(), // Uncomment when assessing bundle size
],
resolve: {
alias: {
'@': assetPath
},
modules: [
'node_modules'
],
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: file => (/node_modules/.test(file) && !/\.vue\.js/.test(file)),
use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } }
},
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'style-loader',
'css-loader',
]
}
]
},
optimization: {
chunkIds: 'named',
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true
}
}
}
},
output: {
path: path.resolve(__dirname, 'locuszoom_plotting_service/static/webpack_bundles'), // Should be in STATICFILES_DIRS,
publicPath: '/static/', // Should match Django STATIC_URL
filename: '[name].js', // In prod, Django will apply its own hashing to static asset filenames
chunkFilename: '[id]-[chunkhash].js' // DO have Webpack hash chunk filename, see below
},
devServer: {
writeToDisk: true, // Write files to disk in dev mode, so Django can serve the assets
},
};