-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
137 lines (121 loc) · 3.97 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
// Node Packages
const path = require('path');
const url = require('url');
// Webpack Packages
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
// Build Files
const setHotReload = require('./build/utils/setHotReload.js');
// const configDev = require('./build/webpack.dev.js');
const configProd = require('./build/webpack.prod.js');
// Configuration
const config = {
host: 'rakenwebsite.test',
port: 8080, // Only used in devServer
themePath: path.resolve(__dirname),
sourcePath: path.resolve(__dirname, './src'),
distPath: path.resolve(__dirname, './dist'),
themePublicPath: '/site/themes/raken-2.0/',
distPublicPath: '/site/themes/raken-2.0/dist/'
};
/**
* This is the base configuration
*/
module.exports = (env, argv) => {
setHotReload(argv.mode, config);
const baseConfig = {
entry: {
runtime: ['promise-polyfill/src/polyfill'],
main: './src/script/index.js',
style: './src/styles/main.scss'
},
// prettier-ignore
output: {
path: config.distPath,
publicPath: argv.mode === 'production'
? config.distPublicPath
: `//${config.host}:${config.port}` + config.distPublicPath, // Supports HMR
filename: argv.mode === 'production' ? '[name].[contenthash:8].js' : '[name].js',
chunkFilename: argv.mode === 'production' ? '[name].[contenthash:8].bundle.js' : '[name].bundle.js'
},
resolve: {
modules: ['node_modules', config.themePath, `${config.sourcePath}/vue`],
alias: {
'@': config.themePath,
vue$: 'vue/dist/vue.esm.js'
},
extensions: ['.js', '.vue']
},
externals: {},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules\/(?![vue\-disqus])/
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.svg$/,
include: [`${config.sourcePath}/images/svg`],
loader: 'svg-sprite-loader'
},
{
test: /\.(jpe?g|png|gif|svg|woff|woff2)$/,
loader: 'file-loader',
include: [`${config.themePath}/img`, `${config.themePath}/src/fonts`],
options: {
name: '[path][name].[ext]',
publicPath: config.themePublicPath,
emitFile: false
}
}
]
},
optimization: {
runtimeChunk: {
name: 'runtime'
}
},
plugins: [
// prettier-ignore
new MiniCssExtractPlugin({
filename: argv.mode === 'production' ? '[name].[contenthash:8].css' : '[name].css',
chunkFilename: argv.mode === 'production' ? '[name].[contenthash:8].css' : '[name].css'
}),
/**
* Generates a manifest that contains all the initial (CSS & JS) files after code-splitting.
*
* @see WebpackrTags.php on implementation
*/
new ManifestPlugin({
fileName: 'webpackManifest.json',
writeToFileEmit: true,
filter: file => {
// Only initial files and non-sourcemap files are needed.
return file.isInitial && file.name.indexOf('map') < 0;
},
sort: (a, b) => {
// Sort runtime and vendor related files at the top
return new RegExp('runtime|vendor').test(a.name) ? -1 : 1;
}
}),
new VueLoaderPlugin()
],
devtool: argv.mode === 'production' ? 'source-map' : 'inline-source-map'
};
// console.dir(merge(baseConfig, configDev(env, argv, config)));
// console.dir(merge(baseConfig, configProd(env, argv, config)));
/**
* This depending on mode, webpack-merge is used to merge this base
* configuration with either config.dev.js or config.prod.js
*/
return argv.mode === 'production'
? merge(baseConfig, configProd(env, argv, config))
: merge(baseConfig, configDev(env, argv, config));
};