forked from zhenlab-ltri/NemaNode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
144 lines (139 loc) · 4.25 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
const path = require('path');
const fs = require('fs-extra');
const ini = require('ini');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const PostCompilePlugin = require('post-compile-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const SRC_DIR = 'src/client';
const ASSET_PATHS = [
'style/',
'image/'
];
const DIST_DIR = 'dist';
const license = fs.readFileSync('LICENSE', 'utf-8');
const { google_analytics_id } = ini.parse(
fs.readFileSync(path.join(__dirname, 'config.ini'), 'utf-8')
).google_analytics;
module.exports = (env, argv) => {
let googleAnalyticsCode = '';
if (argv.mode == 'production' && google_analytics_id !== '') {
googleAnalyticsCode = `
<script async src="https://www.googletagmanager.com/gtag/js?id=${google_analytics_id}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${google_analytics_id}');
</script>`
}
return {
entry: {
'nemanode': './src/client/js/init.js',
'nemanode-style': './src/client/scss/main.scss',
},
devtool: 'inline-source-map',
output: {
path: path.resolve(__dirname, DIST_DIR),
filename: 'js/[name].[contenthash].js'
},
optimization: {
moduleIds: 'hashed',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'libs',
chunks: 'all',
},
},
},
},
/*resolve: {
alias:{
'three/OrbitControls': path.join(__dirname, 'node_modules/three/examples/js/controls/OrbitControls.js'),
'three/OrthographicTrackballControls': path.join(__dirname, 'node_modules/three/examples/js/controls/OrthographicTrackballControls.js'),
'three/LineSegments2': path.join(__dirname, 'node_modules/three/examples/js/lines/LineSegments2.js'),
'three/LineSegmentsGeometry': path.join(__dirname, 'node_modules/three/examples/js/lines/LineSegmentsGeometry.js'),
'three/LineMaterial': path.join(__dirname, 'node_modules/three/examples/js/lines/LineMaterial.js'),
'three/GLTFLoader': path.join(__dirname, 'node_modules/three/examples/js/loaders/GLTFLoader.js'),
vue: 'vue/dist/vue.esm.js'
}
},*/
plugins: [
new MiniCssExtractPlugin({
filename: 'style/[name].[contenthash].css',
}),
new ExtraWatchWebpackPlugin({
dirs: [
'src/client/scss/',
'src/client/image/'
]
}),
new CleanWebpackPlugin(), // clears unused files after build.
/*new webpack.ProvidePlugin({
'THREE': 'three'
}),*/
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new HtmlWebpackPlugin({
hash: true,
template: './src/client/webpack-template.index.html',
inject: 'head',
templateParameters: {
'license': license,
'google_analytics': googleAnalyticsCode
},
}),
new PostCompilePlugin(() => {
ASSET_PATHS.forEach( path => {
fs.copySync(`${SRC_DIR}/${path}`, `${DIST_DIR}/${path}`);
} );
}),
],
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(s[ac]ss)$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false, //don't follow images and fonts.
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
autoprefixer
]
}
},
'sass-loader',
]
}
]
},
watchOptions: {
poll: true,
ignored: /node_modules/
}
}
};