-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (74 loc) · 2.03 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
const path = require('path')
const manifestJson = require('./manifest.json')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin')
const ZipPlugin = require('zip-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { CraftExtensionApiPlugin } = require('@craftdocs/craft-extension-api-sdk')
module.exports = (env, argv) => {
const isProd = argv.mode === 'production'
return {
entry: {
app: './src/index.ts'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: "/"
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json']
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
// Enables including CSS by doing "import './file.css'" in your TypeScript code
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
// Allows you to use import './file.png'" in your code to get a data URI
{
test: /\.(svg|png|bmp|jpg|jpeg|webp|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 100000000,
},
},
],
}
]
},
plugins: [
new CraftExtensionApiPlugin(),
new HtmlWebpackPlugin({
inject: 'body',
template: path.resolve(__dirname, 'src/index.html'),
chunks: ['app']
}),
isProd && new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/app/]),
isProd && new CopyPlugin({
patterns: [
{ from: 'manifest.json' },
{ from: 'icon.png' }
],
}),
isProd && new ZipPlugin({
filename: manifestJson.fileName,
extension: 'craftx',
include: [
'app.js.LICENSE.txt',
'index.html',
'manifest.json',
'icon.png'
]
})
].filter(Boolean)
}
}