-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (102 loc) · 2.82 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
const { resolve } = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const webpackMerge = require('webpack-merge')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin')
const rootPath = resolve(__dirname, '.')
const srcPath = resolve(rootPath, './src')
const staticPath = resolve(rootPath, './static')
const distPath = resolve(rootPath, './dist')
const cratePath = resolve(rootPath, '.')
const appPath = resolve(srcPath, './app')
const workerPath = resolve(srcPath, './worker')
const baseConfig = {
module: {
rules: [
{ test: /\.vue$/, loader: 'vue-loader' },
{
test: /\.css$/,
use: [ 'vue-style-loader', 'css-loader' ],
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
loader: 'file-loader',
},
],
},
resolve: {
extensions: ['.js', '.ts', '.wasm'],
},
plugins: [
new VueLoaderPlugin(),
new WasmPackPlugin({
crateDirectory: cratePath,
forceMode: 'release',
}),
new CopyWebpackPlugin([{ from: staticPath, to: distPath }]),
],
}
const appConfig = webpackMerge(baseConfig, {
entry: {
app: [
'tslib',
resolve(appPath, './index.ts'),
],
},
output: {
path: distPath,
filename: '[name].[hash].js',
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
configFile: resolve(appPath, './tsconfig.json'),
},
include: [srcPath],
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: resolve(distPath, './index.html'),
template: resolve(rootPath, './index.html'),
inject: true,
}),
],
})
// worker-loader のバグでchunk情報やモジュール読み込み関数の初期化を行うコード (webpackBootstrap,
// ref: https://github.com/webpack/webpack/blob/a4e5f63d9d370b191bb9586570bc22bf2947e390/lib/MainTemplate.js)
// がエントリポイントだけに埋め込まれて Worker 内に埋め込まれないので, ここでは Worker を別のエントリポイントに
// 分けて問題を回避する.
// ref: https://github.com/webpack/webpack/issues/6629
const searchWorkerConfig = webpackMerge(baseConfig, {
target: 'webworker',
entry: {
'worker': [
resolve(workerPath, './worker.ts'),
],
},
output: {
path: distPath,
filename: 'worker.js',
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
configFile: resolve(workerPath, './tsconfig.json'),
},
include: [srcPath],
},
],
},
})
module.exports = [appConfig, searchWorkerConfig]