forked from owncloud/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
147 lines (141 loc) · 3.96 KB
/
webpack.common.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
const path = require('path')
const fs = require('fs')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const WebpackCopyPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackVersionFilePlugin = require('webpack-version-file-plugin')
const execa = require('execa')
const gitHash = execa.sync('git', ['rev-parse', '--short', 'HEAD']).stdout
const gitNumCommits = Number(execa.sync('git', ['rev-list', 'HEAD', '--count']).stdout)
const gitDirty = execa.sync('git', ['status', '-s', '-uall']).stdout.length > 0
const appFolder = path.resolve(__dirname, 'apps')
let apps = []
let favicon = './themes/owncloud/favicon.jpg'
var config
if (fs.existsSync('config.json')) {
config = require('./config.json')
} else {
config = require('./tests/drone/config.json')
}
if (fs.existsSync(`./themes/${config.theme}/favicon.jpg`)) {
favicon = `./themes/${config.theme}/favicon.jpg`
}
config.apps
.forEach(function (mod) {
if (fs.existsSync(path.resolve(appFolder, mod))) {
var modPath = {
from: path.resolve('apps', mod, 'dist'),
to: path.resolve(__dirname, 'dist', 'apps', mod)
}
apps.push(modPath)
}
})
const sourceFiles = [{
from: path.resolve(__dirname, 'themes/**'),
to: path.resolve(__dirname, 'dist')
}, {
from: path.resolve(__dirname, 'node_modules', 'requirejs', 'require.js'),
to: path.resolve(__dirname, 'dist', 'node_modules', 'requirejs')
}]
for (let file of sourceFiles) {
apps.push(file)
}
apps.push({
from: path.resolve(__dirname, 'static', 'config.default.json'),
to: path.resolve(__dirname, 'dist', 'static', 'config.default.json')
})
module.exports = {
plugins: [
new WebpackVersionFilePlugin({
packageFile: path.join(__dirname, 'package.json'),
template: path.join(__dirname, 'src/version.ejs'),
outputFile: path.join('build', 'version.json'),
extras: {
'githash': gitHash,
'gitNumCommits': gitNumCommits,
'timestamp': Date.now(),
'dirty': gitDirty
}
}), new WebpackCopyPlugin(apps),
new HtmlWebpackPlugin({
template: 'index.html',
favicon: favicon
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'css/[name].css',
chunkFilename: 'css/[name].[id].css'
})
],
entry: {
core: [
'whatwg-fetch',
'./src/phoenix.js'
]
},
output: {
filename: 'core/[name].bundle.js',
chunkFilename: 'core/[name].[id].bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
include: [
/src/
]
},
{
test: /\.jsx?$/,
include: /node_modules\/(?=(vuex-persist)\/).*/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '11'
}
}
]
]
}
}
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
include: [/node_modules\/material-design-icons-iconfont\/dist/, /static\/fonts\/ocft\/font/],
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: '../fonts',
outputPath: 'fonts'
}
}]
}, {
enforce: 'pre',
test: /\.(js|vue)$/,
exclude: /node_modules/,
loader: 'eslint-loader'
}, {
test: /\.vue$/,
loader: 'vue-loader',
exclude: [/node_modules/]
}, {
test: /\.(sa|sc|c)ss$/,
include: [/node_modules/, /src/, /static/],
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader'
]
}]
}
}