-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebpack.config.js
146 lines (138 loc) · 4.58 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
/* eslint-env node */
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { NoEmitOnErrorsPlugin, DefinePlugin } = require('webpack');
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
const ASSET_PATH = 'assets';
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
mode: devMode ? 'development' : 'production',
devtool: 'source-map',
recordsPath: path.join(__dirname, '.records'),
entry: {
index: './src/index.ts',
results: './src/results.ts',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: `${ASSET_PATH}/[name].[hash].js`,
chunkFilename: `${ASSET_PATH}/[id].[hash].js`,
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
devServer: {
static: './dist',
},
module: {
rules: [
{
test: /\.tsx?$/,
include: [
path.resolve(__dirname, '../typings'),
path.resolve(__dirname, 'typings'),
path.resolve(__dirname, 'src'),
],
use: [
{
loader: 'ts-loader',
},
],
},
{
test: /\.(png|jpe?g|svg|gif|ttf|woff2?|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/i,
use: [
{
loader: 'file-loader',
options: {
name: `${ASSET_PATH}/[hash].[ext]`,
},
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
optipng: { optimizationLevel: 7 },
gifsicle: { interlaced: false },
},
},
],
},
{
test: /\.less$/,
include: path.resolve(__dirname, './less'),
use: [
MiniCssExtractPlugin.loader,
'css-loader',
// 'postcss-loader',
'less-loader',
],
},
{
test: /\.css$/,
include: path.resolve(__dirname, './node_modules/monaco-editor'),
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.ttf$/,
include: path.resolve(__dirname, './node_modules/monaco-editor'),
type: 'asset/resource',
},
],
},
plugins: [
// don't emit output when there are errors
new NoEmitOnErrorsPlugin(),
// add monaco editor
new MonacoEditorWebpackPlugin({
languages: ['json', 'javascript', 'typescript'],
}),
// extract inline css into separate 'styles.css'
new MiniCssExtractPlugin({
filename: `${ASSET_PATH}/[name].[hash].css`,
chunkFilename: `${ASSET_PATH}/[id].[hash].css`,
}),
// create marketing html
new HtmlWebpackPlugin({
filename: 'index.html',
template: './html/index.ejs',
title: 'Pixi Playground',
description: 'Create and view demos using pixi.js.',
url: 'http://pixiplayground.com',
cache: true,
chunks: ['index'],
}),
// create marketing html
new HtmlWebpackPlugin({
filename: 'results.html',
template: './html/results.ejs',
title: 'Pixi Playground Results',
description: 'Pixi Playground Results',
url: 'http://pixiplayground.com',
cache: true,
chunks: ['results'],
}),
// copy some static assets favicon stuff
new CopyWebpackPlugin({
patterns: [
{
from: './html/favicons/*',
to: '[name][ext]',
},
{
from: './definitions/**',
},
],
}),
// add some extra defines
new DefinePlugin({
__BASE_ORIGIN__: JSON.stringify(process.argv.find(v => v.includes('webpack-dev-server')) ? 'http://localhost:3000' : ''),
}),
],
};