-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
61 lines (59 loc) · 1.59 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const name = require('./package.json').name;
const version = require('./package.json').version;
const mode = process.env.NODE_ENV || 'production';
const plugins = ['accept-terms', 'validate-contact-information', 'progress-bar'];
const config = {
mode,
target: 'web',
entry: {
loader: './src/loader.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'shopify-plugin-[name].min.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['css-loader', 'postcss-loader']
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VERSION': JSON.stringify(version)
}),
new HtmlWebpackPlugin({
plugins: plugins
.map(plugin => {
return `<li><a href="${plugin}.html">${plugin} plugin </a></li>`;
})
.toString()
.replace(/,/g, ' '),
template: './examples/index.html'
})
],
devServer: {
port: 3000
}
};
plugins.forEach(plugin => {
const pluginIdentifier = plugin;
console.log('Registering plugin', plugin);
config.entry[plugin] = `./src/plugins/${plugin}.js`;
config.plugins.push(
new HtmlWebpackPlugin({
template: `./examples/${plugin}/${plugin}.html`,
filename: `${plugin}.html`,
inject: false,
version,
install: `//cdn.jsdelivr.net/gh/nerdsofalltrades/${name}@${version}/dist/shopify-plugin-loader.min.js`
})
);
});
module.exports = config;