forked from elementary/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
68 lines (58 loc) · 1.59 KB
/
webpack.config.babel.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
/**
* webpack.config.babel.js
* Builds mvp assets for use in a browser
*
* @exports {Object} styles - configuration object for style assets
* @exports {Object} scripts - configuration object for script assets
* @exports {Array} default - configuration objects for webpack
*/
import path from 'path'
import glob from 'glob'
import { fileURLToPath } from "url"
import { WebpackManifestPlugin } from 'webpack-manifest-plugin'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const scriptPattern = path.resolve('_scripts', 'pages', '**', '*.js')
/*
* Everthing past this point is plugin configuration. Do not edit unless you
* know what you are doing.
*/
const scriptFiles = {}
glob.sync(scriptPattern).forEach((p) => {
const name = p
.replace(path.resolve(__dirname, '_scripts', 'pages') + path.sep, '')
.replace('.js', '')
scriptFiles[name] = p
})
export default {
mode: 'production',
devtool: 'source-map',
entry: scriptFiles,
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'scripts'),
publicPath: '/scripts',
},
module: {
rules: [{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
}]
},
resolve: {
alias: {
'~': path.resolve(__dirname, '_scripts')
}
},
optimization: {
runtimeChunk: 'single',
},
plugins: [
new WebpackManifestPlugin({
'basePath': 'scripts/'
})
]
}