-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·133 lines (126 loc) · 3.4 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
var BundleTracker = require('webpack-bundle-tracker');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var path = require('path');
var url = require('url');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var resolve = path.resolve.bind(path, __dirname);
var extractCssPlugin;
var fileLoaderPath;
var output;
var reactPath;
var reactDomPath;
if (process.env.NODE_ENV === 'production') {
const baseStaticPath = process.env.STATIC_URL || '/static/';
const publicPath = url.resolve(baseStaticPath, 'assets/');
reactPath = 'node_modules/react/cjs/react.production.min.js';
reactDomPath = 'node_modules/react-dom/cjs/react-dom.production.min.js';
output = {
path: resolve('engine/static/assets/'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
publicPath: publicPath
};
fileLoaderPath = 'file-loader?name=[name].[hash].[ext]';
extractCssPlugin = new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
chunkFilename: '[id].[chunkhash].css'
});
} else {
reactPath = 'node_modules/react/cjs/react.development.js';
reactDomPath = 'node_modules/react-dom/cjs/react-dom.development.js';
output = {
path: resolve('engine/static/assets/'),
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/static/assets/'
};
fileLoaderPath = 'file-loader?name=[name].[ext]';
extractCssPlugin = new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css'
});
}
var bundleTrackerPlugin = new BundleTracker({
filename: 'webpack-bundle.json'
});
var providePlugin = new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: 'popper.js',
'query-string': 'query-string'
});
var config = {
entry: {
dashboard: './engine/static/dashboard/js/dashboard.js',
'dashboard-next': './engine/static/dashboard-next/index.tsx',
},
output: output,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
'sourceMap': true
}
},
{
loader: 'postcss-loader',
options: {
'sourceMap': true,
'plugins': function () {
return [autoprefixer];
}
}
},
{
loader: 'sass-loader',
options: {
'sourceMap': true
}
}
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'awesome-typescript-loader'
},
{
test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/,
loader: fileLoaderPath,
include: [
resolve('node_modules'),
resolve('engine/static/fonts'),
resolve('engine/static/images'),
resolve('engine/static/dashboard/images')
]
}
]
},
plugins: [
bundleTrackerPlugin,
extractCssPlugin,
providePlugin
],
resolve: {
alias: {
jquery: resolve('node_modules/jquery/dist/jquery.js'),
react: resolve(reactPath),
'react-dom': resolve(reactDomPath)
},
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
devtool: 'sourceMap'
};
module.exports = config;