forked from nextcloud-libraries/nextcloud-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
161 lines (152 loc) · 4.22 KB
/
Copy pathwebpack.common.js
File metadata and controls
161 lines (152 loc) · 4.22 KB
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
const fs = require('fs')
const gettextParser = require('gettext-parser')
const glob = require('glob')
const md5 = require('md5')
const path = require('path')
const { DefinePlugin } = require('webpack')
const { VueLoaderPlugin } = require('vue-loader')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const nodeExternals = require('webpack-node-externals')
// scope variable
// fallback for cypress testing
const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-vue')
const versionHash = md5(appVersion).slice(0, 7)
const SCOPE_VERSION = JSON.stringify(versionHash)
console.info('This build version hash is', versionHash, '\n')
// https://github.com/alexanderwallin/node-gettext#usage
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
const translations = fs
.readdirSync('./l10n')
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
.map(file => {
const path = './l10n/' + file
const locale = file.slice(0, -'.pot'.length)
const po = fs.readFileSync(path)
const json = gettextParser.po.parse(po)
// Compress translations Content
const translations = {}
for (const key in json.translations['']) {
if (key !== '') {
// Plural
if ('msgid_plural'in json.translations[''][key]) {
translations[json.translations[''][key].msgid] = {
pluralId: json.translations[''][key].msgid_plural,
msgstr: json.translations[''][key].msgstr,
}
continue
}
// Singular
translations[json.translations[''][key].msgid] = json.translations[''][key].msgstr[0]
}
}
return {
locale,
translations,
}
})
module.exports = {
entry: {
ncvuecomponents: path.join(__dirname, 'src', 'index.js'),
...glob.sync('src/components/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/components/', 'Components/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/directives/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/directives/', 'Directives/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/functions/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/functions/', 'Functions/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/mixins/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/mixins/', 'Mixins/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: '[name].js',
libraryTarget: 'umd',
library: ['NextcloudVue', '[name]'],
umdNamedDefine: true,
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
{
loader: 'sass-loader',
options: {
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
/**
* ! needed for resolve-url-loader
*/
sourceMap: true,
sassOptions: {
sourceMapContents: false,
includePaths: [
path.resolve(__dirname, './src/assets'),
],
},
},
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: BabelLoaderExcludeNodeModulesExcept([
'@nextcloud/calendar-js',
'tributejs',
]),
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'url-loader',
},
],
},
plugins: [
new VueLoaderPlugin(),
new DefinePlugin({
SCOPE_VERSION,
TRANSLATIONS: JSON.stringify(translations),
}),
],
resolve: {
extensions: ['*', '.js', '.vue'],
symlinks: false,
// Alias the default server assets path to link to local one
alias: {
'/core/css/../img': path.join(__dirname, 'styleguide/assets/img'),
'/core/css/../fonts': path.join(__dirname, 'styleguide/assets/fonts'),
},
},
}