-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
68 lines (67 loc) · 2.42 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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts')
const TerserPlugin = require('terser-webpack-plugin')
const fs = require('fs')
const obfuscator = require('webpack-obfuscator')
const WebpackObfuscatorPlugin = require('webpack-obfuscator')
module.exports = {
// モジュールバンドルを行う起点となるファイルの指定
// 指定できる値としては、ファイル名の文字列や、それを並べた配列やオブジェクト
// 下記はオブジェクトとして指定した例
entry: {
'js/index': './src/index.ts',
'js/menu': './src/menu.ts',
'css/index': './src/index.scss',
},
// モジュールバンドルを行った結果を出力する場所やファイル名の指定
output: {
path: path.join(__dirname, 'dist'), // "__dirname"はファイルが存在するディレクトリ
filename: '[name].js', // [name]はentryで記述した名前(この設定ならbundle)
environment: {
arrowFunction: false,
},
},
// import文でファイル拡張子を書かずに名前解決するための設定
// 例...「import World from './world'」と記述すると"world.ts"という名前のファイルをモジュールとして探す
resolve: {
extensions: ['.ts', '.js'], // Reactの.tsxや.jsxの拡張子も扱いたい場合は配列内に追加する
//以下を追加
},
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
}, // webpack-dev-serverの公開フォルダ
},
// モジュールに適用するルールの設定(ローダーの設定を行う事が多い)
module: {
rules: [
{
// 拡張子が.tsのファイルに対してTypeScriptコンパイラを適用する
// Reactで用いる.tsxの拡張子にも適用する場合は test:/\.(ts|tsx)$/,
test: /\.ts$/,
loader: 'ts-loader',
},
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'dist/css/index.css',
}),
new WebpackObfuscatorPlugin({
StringArrayEncoding: ['base64', 'rc4'],
}),
new RemoveEmptyScriptsPlugin(),
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
}