forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
157 lines (144 loc) · 4.66 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
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 outputDir = 'dist'
const assetsDir = process.env.TWILL_ASSETS_DIR || 'assets/admin'
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: isProd
? `${assetsDir}/icons/icons${suffix}.[contenthash].svg`
: `${assetsDir}/icons/icons${suffix}.svg`,
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`
}
}
}
}
let 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, '')
}
}
})
]
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,
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}`)
})
}
}
module.exports = config