-
Notifications
You must be signed in to change notification settings - Fork 21
/
configure-app.js
137 lines (131 loc) · 4.07 KB
/
configure-app.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
'use strict'
// libraries
const path = require('path')
// Webpack plugins
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HandlebarsPlugin = require('handlebars-webpack-plugin')
// Additional imports
const cli = require('../utils/cli')
const AppInfo = require('../utils/appinfo')
// define your stuff
const baseDir = path.join(__dirname, '../../')
const buildDir = path.join(baseDir, 'build')
const appinfo = new AppInfo()
const sassTheme = appinfo.sassTheme || 'red'
const PLUGINS = [
new webpack.DefinePlugin({
PROJECT: JSON.stringify(appinfo),
}),
new CleanWebpackPlugin(['build'], {
// Absolute path to your webpack root folder (paths appended to this)
// Default: root of your package
root: baseDir,
// Write logs to console.
verbose: true,
// Use boolean "true" to test/emulate delete. (will not remove files).
// Default: false - remove files
dry: false,
// If true, remove files on recompile.
// Default: false
watch: false,
// Instead of removing whole path recursively,
// remove all path's content with exclusion of provided immediate children.
// Good for not removing shared files from build directories.
exclude: [
'.gitkeep',
'assets'
],
// allow the plugin to clean folders outside of the webpack root.
// Default: false - don't allow clean folder outside of the webpack root
allowExternal: false,
// perform clean just before files are emitted to the output dir
// Default: false
beforeEmit: false,
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css'
}),
new HandlebarsPlugin({
// path to hbs scene entry file(s)
entry: path.join(baseDir, 'src', 'hbs', '*.hbs'),
// output path and filename(s). This should lie within the webpacks output-folder
// if ommited, the input filepath stripped of its extension will be used
output: path.join(buildDir, '[name].html'),
// data passed to main hbs template: `main-template(data)`
data: appinfo,
// globbed path to partials, where dir/filename is unique
partials: [
path.join(baseDir, 'src', 'hbs', 'partials', '**', '*.hbs')
],
// hooks
onBeforeSetup: function(Handlebars) {
cli.info('Handlebars version: ', Handlebars.VERSION)
},
// onBeforeAddPartials: function(Handlebars, partialsMap) {
// // cli.info('update Handlebars partials')
// },
// onBeforeCompile: function (Handlebars, templateContent) {
// if (templateContent.startsWith('<a-scene')) {
// return `{{> aframe/header}}${templateContent}{{> aframe/footer}}`
// }
// return `{{> html/header}}${templateContent}{{> html/footer}}`
// },
// onBeforeRender: function(Handlebars, data) {
// cli.info('onBeforeRender: ')
// data.app = appinfo
// },
// onBeforeSave: function(Handlebars, resultHtml, filename) {},
// onDone: function(Handlebars, filename) {
// cli.ok(`updated: ${filename}`)
// }
})
]
cli.info('load app config from ./devel/webpack/configure-app.js')
module.exports = {
name: 'app',
entry: {
app: [
path.join(baseDir, 'src', 'js', 'app.js'),
path.join(baseDir, 'src', 'style', 'app.scss'),
],
'lib-aframe': [
path.join(baseDir, 'src', 'js', 'lib-aframe.js'),
],
'background.worker': [
path.join(baseDir, 'src', 'js', 'background.worker.js'),
]
},
plugins: PLUGINS,
output: {
path: path.join(buildDir, 'app'),
filename: path.join('js', '[name].js'),
globalObject: 'this'
},
module: {
rules: [{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
data: `$theme: ${sassTheme};`,
}
}
],
}, {
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
},
}