-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
97 lines (93 loc) · 3.2 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const BundleTracker = require('webpack-bundle-tracker');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = (env, argv) => {
const DEV = argv ? argv.mode === 'development' : true;
if (DEV) console.log(`Webpack running in DEVELOPMENT mode`);
else console.log(`Webpack running in PRODUCTION mode`);
return {
entry: {
app: './js/app.ts',
lib: './js/lib.js',
styles: './styles/main.sass',
},
output: {
path: path.resolve(__dirname, './dist/webpack'),
publicPath: '/static/',
filename: DEV ? "[name].js" : '[name].[chunkhash].js',
},
optimization: {
// TODO: Can't do this with current django-webpack-loader. There is a fork to do this but will leave
// until we have a large enough app to make it worth it.
// See: https://github.com/owais/webpack-bundle-tracker/pull/41#issuecomment-463709521
// splitChunks: {
// chunks: 'all',
// },
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.([tj])s$/,
use: [
'babel-loader',
],
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: DEV,
},
},
{loader: 'css-loader', options: {importLoaders: 1}},
'postcss-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
indentedSyntax: true
},
}
}
],
},
{
test: /\.(png|jpe?g|gif|svg|ttf|eot|woff2?)$/i,
use: [
{
loader: 'file-loader',
},
],
},
]
},
resolve: {
extensions: ['.ts', '.js', '.vue', '.json'],
alias: {
'assets': path.resolve(__dirname, 'assets'),
'vue$': 'vue/dist/vue.esm.js',
}
},
plugins: [
new MiniCssExtractPlugin({
filename: DEV ? "[name].css" : "[name].[chunkhash].css"
}),
new BundleTracker({
filename: 'dist/webpack-stats.json'
}),
new VueLoaderPlugin(),
],
devtool: DEV ? '#eval-source-map' : '#source-map',
performance: {
hints: 'warning'
},
}
};