-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·187 lines (185 loc) · 5.04 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const webpack = require('webpack');
const path = require('path');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const MODE = 'production';
const enabledSourceMap = MODE === "development";
module.exports = {
// context: __dirname,
cache: true,
mode: MODE,
// メインとなるJavaScriptファイル(エントリーポイント)
entry: {
bundle: path.resolve(__dirname, './src/main.js'),
},
// ファイルの出力設定
output: {
// 出力ファイルのディレクトリ名
path: path.resolve(__dirname, './dist/'),
// publicPath: '/assets/js',
filename: 'assets/js/[name].js',
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
// node_modules配下のモジュールをバンドル対象とする
test: /node_modules/,
name: "vendor",
chunks: "initial",
enforce: true
}
}
},
minimizer: [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})]
},
devServer: {
open: true,//ブラウザを自動で開く
contentBase: path.join(__dirname, 'dist'),// HTML等コンテンツのルートディレクトリ
watchContentBase: true,//コンテンツの変更監視をする
port: 3000, // ポート番号
historyApiFallback: true,
hot: true
},
module: {
rules: [
{
// 拡張子 .js の場合
test: /\.js$/,
exclude: /(node_modules)/,
// include: [
// srcPath,
// path.resolve(__dirname, 'node_modules/gsap'),
// ],
use: [
{
// Babel を利用する
loader: "babel-loader",
// Babel のオプションを指定する
options: {
"presets": [
["@babel/preset-env", {
"useBuiltIns": false,
}],
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-syntax-dynamic-import"
]
}
}
]
},
{
test: /\.vue$/,
use: [
{
loader: "vue-loader"
}
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
// オプションでCSS内のurl()メソッドの取り込みを禁止する
url: false,
sourceMap: enabledSourceMap,
// 0 => no loaders (default);
// 1 => postcss-loader;
// 2 => postcss-loader, sass-loader
importLoaders: 2
}
},
// PostCSSのための設定
{
loader: "postcss-loader",
options: {
sourceMap: enabledSourceMap,
plugins: [
require("autoprefixer")({
grid: true
})
]
}
},
{
loader: 'sass-loader',
options: {
data: `
@import "./src/assets/_sass/setting/_variables.scss";
@import "./src/assets/_sass/setting/_functions.scss";
@import "./src/assets/_sass/mixin/_mixin.scss";
`,
sourceMap: enabledSourceMap
},
}
],
},
{
test: /\.pug$/,
use: [
{
loader: "pug-plain-loader"
}
]
},
{
test: /\.(jpg|png|gif|svg)$/,
loaders: 'url-loader'
},
{
test: /\.(glsl|vs|fs|vert|frag)$/,
exclude: /node_modules/,
use: [
'raw-loader',
'glslify-loader'
]
}
]
},
resolve: {
extensions: ['.js', '.vue'],// importするときに省略できる拡張子の設定
// modules: [// モジュールを読み込むときに検索するディレクトリの設定
// 'node_modules'
// ],
alias: {// 例えばmain.js内で `import Vue from 'vue';` と記述したときの`from vue`が表すファイルパスを指定
vue$: 'vue/dist/vue.esm.js',
// vuex$: 'vuex/dist/vuex.js'
}
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
'THREE': 'three/build/three'
}),
new VueLoaderPlugin(),
new CopyWebpackPlugin(
[
{
context: './src/',
from: 'assets/img',
to: 'assets/img',
},
],
),
new CopyWebpackPlugin(
[
{
context: './src/',
from: '**.html',
to: '',
},
],
),
new MiniCssExtractPlugin({filename: 'assets/css/style.min.css'}),
// new HtmlWebpackPlugin({title: 'Revision control'})
]
};