-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
172 lines (164 loc) · 4.5 KB
/
webpack.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
// nodeに元から入っているモジュール
// ファイルパスの文字列の解析、操作などができる
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = (env, argv) => {
// argv.modeにはwebpackを実行したmodeが格納されている
// 例えば webpack --mode development と実行すれば
// argv.mode には 'development' が格納されている
// そのためdevelopmentモードで実行したかどうかを判定できる
// モードの確認.
let IS_DEVELOPMENT = false;
if (argv.mode === 'development') {
IS_DEVELOPMENT = true;
}
// 環境(開発か本番)
let mode;
if (argv.env === 'dev') {
mode = 'dev';
} else if (argv.env === 'prod') {
mode = 'prod';
}
const settingDeployApp = require(`./env/${mode}_setting_deploy_app.js`);
const types = ['desktop', 'mobile'];
const entries = {};
Object.keys(settingDeployApp.contents).forEach(name => {
const contents = settingDeployApp.contents[name];
types.forEach(type => {
if (contents[type] && contents[type].js) {
contents[type].js.forEach(file => {
if (file.match(/^(http|https):/)) {
return;
}
// console.log(file);
const fileArray = file.split('/');
if (fileArray.length !== 2) {
return;
}
const fileName = fileArray.slice(-1)[0].replace(/\.js$/, '');
entries[fileArray[0]] =
'./src/' + [fileArray[0] + '/' + fileName + '.js'];
});
}
});
});
return {
// 開発元
entry: entries,
// 開発元をコンパイルした時の出力先を設定
output: {
path: path.join(__dirname, './app'),
filename: '[name]/app.js',
},
// // 各モジュールのインポート文が相対パスだらけにならないようにルートを設定
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'env'),
],
alias: {
vue$: 'vue/dist/vue.esm.js',
},
},
externals: {
kintone: 'kintone',
},
module: {
rules: [
/**
* jsファイルをbabel-loderを利用して古いバージョンのJSに出力する
*/
{
// test: /\.js$/,
// 公式ドキュメントにあわせる
// https://github.com/babel/babel-loader
test: /\.m?js$/,
// exclude: /node_modules/,
// 公式ドキュメントを参照
// https://github.com/babel/babel-loader
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'babel-loader',
},
],
},
/**
*
* woffファイル
*
**/
{
test: /\.(otf|eot|svg|ttf|woff|woff2)(\?.+)?$/,
use: [
{
loader: 'url-loader',
options: {
esModule: false,
},
},
],
},
/**
*
* CSSの設定
*
**/
{
test: /\.css$/,
use: [
{
loader: 'style-loader!css-loader',
},
],
},
/**
* SASSの設定
*/
{
test: /\.scss/,
use: [
// linkタグを出力する機能
'style-loader',
// CSSをバンドルするための機能
{
loader: 'css-loader',
options: {
// オプションでCSS内のurl()メソッドの取り込みを禁止する
url: false,
// ソースマップの利用の有無
sourceMap: IS_DEVELOPMENT,
// 0 => no loaders(defalut)
// 1 => postcss-loader;
// 2 => postcss-loader, sass-loader
importLoaders: 2,
},
},
// Sassコンパイル
{
loader: 'sass-loader',
options: {
// ソースマップの利用有無
sourceMap: IS_DEVELOPMENT,
},
},
],
},
/**
*
* Vue
*
**/
{
test: /\.vue$/,
loader: 'vue-loader',
},
],
},
plugins: [
// make sure to include the plugin!
new VueLoaderPlugin(),
],
};
};