UNPKG

1.22 kBJavaScriptView Raw
1const path = require('path');
2const webpack = require('webpack');
3
4const configuration = {
5 entry: ['./src/bundle.js'],
6 output: {
7 path: path.resolve(__dirname, './dist'),
8 filename: 'craft-ai.js'
9 },
10 plugins: [
11 new webpack.DefinePlugin({
12 'process.env': {
13 'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
14 'CRAFT_TOKEN': undefined,
15 'CRAFT_URL': undefined
16 }
17 })
18 ],
19 module: {
20 rules: [
21 {
22 test: /\.js$/,
23 loader: 'babel-loader',
24 exclude: /node_modules/,
25 options: {
26 cacheDirectory: true,
27 presets: [
28 ['env', {
29 targets: {
30 browsers: 'last 2 versions, > 5%'
31 },
32 modules: false,
33 useBuiltIns: true
34 }]
35 ]
36 }
37 }
38 ]
39 }
40};
41
42if (process.env.NODE_ENV === 'production') {
43 configuration.entry.unshift(require.resolve('babel-polyfill'), require.resolve('whatwg-fetch'));
44 configuration.output.filename = 'craft-ai.min.js';
45 configuration.plugins.push(new webpack.optimize.UglifyJsPlugin({
46 compress: {
47 warnings: false
48 },
49 comments: false
50 }));
51}
52
53module.exports = configuration;