forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
182 lines (165 loc) · 5.64 KB
/
vue.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const fs = require("fs")
const path = require('path')
const isProd = process.env.NODE_ENV === 'production'
// Define global vue variables
process.env.VUE_APP_NAME = process.env.VUE_APP_NAME || 'TWILL'
// eslint-disable-next-line no-console
console.log('\x1b[32m', `\n🔥 Building Twill assets in ${isProd ? 'production' : 'dev'} mode.`)
/**
* For configuration
* @see: https://github.com/johnagan/clean-webpack-plugin
*/
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
/**
* For configuration
* @see: https://github.com/cascornelissen/svg-spritemap-webpack-plugin
*/
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin')
/**
* For configuration
* @see: https://github.com/webdeveric/webpack-assets-manifest
*/
const WebpackAssetsManifest = require('webpack-assets-manifest')
/**
* For configuration
* @see: https://github.com/Turbo87/webpack-notifier
*/
const WebpackNotifierPlugin = require('webpack-notifier')
const srcDirectory = 'frontend'
const partialsDirectory = '../views/partials'
const outputDir = isProd ? 'dist' : (process.env.TWILL_DEV_ASSETS_PATH || 'dist')
const assetsDir = process.env.TWILL_ASSETS_DIR || 'assets/admin'
// Only works with laravel valet.
const useHttps = process.env.TWILL_DEV_MODE_SSH ? process.env.TWILL_DEV_MODE_SSH === 'true' : false
const pages = {
'main-buckets': `${srcDirectory}/js/main-buckets.js`,
'main-dashboard': `${srcDirectory}/js/main-dashboard.js`,
'main-form': `${srcDirectory}/js/main-form.js`,
'main-listing': `${srcDirectory}/js/main-listing.js`,
'main-free': `${srcDirectory}/js/main-free.js`
}
const svgConfig = (suffix = null) => {
suffix = suffix !== null ? `-${suffix}` : ''
return {
output: {
filename: `${partialsDirectory}/icons/icons${suffix}-svg.blade.php`,
chunk: {
name: `icons${suffix}`
}
},
sprite: {
prefix: 'icon--'
},
styles: {
filename: `~svg-sprite-icons${suffix}.scss`,
variables: {
sprites: `icons${suffix}-sprites`,
sizes: `icons${suffix}-sizes`,
variables: `icons${suffix}-variables`,
mixin: `icons${suffix}-sprites-mixin`
}
}
}
}
const plugins = [
new CleanWebpackPlugin(),
new SVGSpritemapPlugin(`${srcDirectory}/icons/**/*.svg`, svgConfig()),
new SVGSpritemapPlugin(`${srcDirectory}/icons-files/**/*.svg`, svgConfig('files')),
new SVGSpritemapPlugin(`${srcDirectory}/icons-wysiwyg/**/*.svg`, svgConfig('wysiwyg')),
new WebpackAssetsManifest({
output: `${assetsDir}/twill-manifest.json`,
publicPath: true,
customize (entry, original, manifest, asset) {
const search = new RegExp(`${assetsDir.replace(/\//gm, '\/')}\/(css|fonts|js|icons)\/`, 'gm')
return {
key: entry.key.replace(search, '')
}
}
})
]
function isDirEmpty(dirname) {
return fs.promises.readdir(dirname).then(files => {
return files.length === 0;
});
}
if (!isDirEmpty(`${srcDirectory}/icons-custom/`)) {
plugins.push(new SVGSpritemapPlugin(`${srcDirectory}/icons-custom/**/*.svg`, svgConfig('custom')));
}
if (!isProd) {
plugins.push(new WebpackNotifierPlugin({
title: 'Twill',
contentImage: path.join(__dirname, 'docs/.vuepress/public/favicon-180.png')
}))
}
// Define npm module resolve order: 1. local (Twill), 2. root (App)
const appModuleFolder = path.resolve(__dirname, '../../../node_modules') // vendor/area17/twill/
const resolveModules = ['node_modules']
if (fs.existsSync(appModuleFolder)) {
resolveModules.push(appModuleFolder)
}
const config = {
// Define base outputDir of build
outputDir: outputDir,
// Define root asset directory
assetsDir: assetsDir,
// Remove sourcemaps for production
productionSourceMap: false,
css: {
loaderOptions: {
// define global settings imported in all components
sass: {
prependData: `@import "~styles/setup/_settings.scss";`
}
}
},
// Define entries points
pages,
devServer: {
hot: true,
https: useHttps,
disableHostCheck: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
},
runtimeCompiler: true,
configureWebpack: {
resolve: {
alias: {
'prosemirror-tables': path.join(__dirname, 'node_modules/prosemirror-tables/src/index.js'),
'prosemirror-state' : path.join(__dirname, 'node_modules/prosemirror-state/src/index.js'),
'prosemirror-view' : path.join(__dirname, 'node_modules/prosemirror-view/src/index.js'),
'prosemirror-transform' : path.join(__dirname, 'node_modules/prosemirror-transform/src/index.js')
},
modules: resolveModules
},
plugins,
performance: {
hints: false
}
},
chainWebpack: config => {
// Update default vue-cli aliases
config.resolve.alias.set('fonts', path.resolve(`${srcDirectory}/fonts`))
config.resolve.alias.set('@', path.resolve(`${srcDirectory}/js`))
config.resolve.alias.set('styles', path.resolve(`${srcDirectory}/scss`))
// Delete HTML related webpack plugins by page
Object.keys(pages).forEach(page => {
config.plugins.delete(`html-${page}`)
config.plugins.delete(`preload-${page}`)
config.plugins.delete(`prefetch-${page}`)
})
}
}
if (useHttps) {
const homeDir = process.env.HOME;
const host = process.env.APP_URL.split('//')[1] ?? process.env.APP_URL;
// This takes the ssh certificates from your `valet secure` domain so that browsers (Looking at safari) stop
// complaining about it.
config.devServer.host = host;
config.devServer.https = {
key: fs.readFileSync(path.resolve(homeDir, `.config/valet/Certificates/${host}.key`)),
cert: fs.readFileSync(path.resolve(homeDir, `.config/valet/Certificates/${host}.crt`)),
}
}
module.exports = config