Doodle3D-Core/webpack.config.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-12-07 16:21:10 +01:00
const webpack = require('webpack');
2017-11-15 15:13:49 +01:00
const path = require('path');
2017-12-05 16:28:19 +01:00
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2017-11-15 15:13:49 +01:00
const HTMLWebpackPlugin = require('html-webpack-plugin');
2017-12-07 16:21:10 +01:00
const CordovaPlugin = require('webpack-cordova-plugin');
2017-11-15 15:13:49 +01:00
2017-11-15 17:00:30 +01:00
const devMode = process.env.NODE_ENV !== 'production';
2017-12-07 16:21:10 +01:00
const appMode = process.env.TARGET === 'app';
2017-11-15 17:00:30 +01:00
2017-11-15 15:13:49 +01:00
const babelLoader = {
loader: 'babel-loader',
options: {
presets: [
require('babel-preset-env'),
require('babel-preset-react')
],
plugins: [
require('babel-plugin-transform-object-rest-spread'),
require('babel-plugin-transform-class-properties'),
require('babel-plugin-transform-runtime')
],
babelrc: false
}
};
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
alias: {
2017-11-15 17:00:30 +01:00
'doodle3d-core': path.resolve(__dirname, devMode ? 'module' : 'lib'),
2017-11-15 15:13:49 +01:00
'clipper-lib': '@doodle3d/clipper-lib',
'clipper-js': '@doodle3d/clipper-js',
'cal': '@doodle3d/cal',
'touch-events': '@doodle3d/touch-events',
'potrace-js': '@doodle3d/potrace-js',
'fill-path': '@doodle3d/fill-path',
2017-11-17 23:08:01 +01:00
'threejs-export-stl': '@doodle3d/threejs-export-stl',
'threejs-export-obj': '@doodle3d/threejs-export-obj'
2017-11-15 15:13:49 +01:00
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: babelLoader
}, { // make THREE global available to three.js examples
test: /three\/examples\/.+\.js/,
use: 'imports-loader?THREE=three'
}, {
test: /\.yml$/,
use: 'yml-loader'
}, {
test: /\.worker.js$/,
use: ['worker-loader', babelLoader]
}, {
test: /\.(png|jpg|gif)$/,
use: {
2017-12-11 11:45:57 +01:00
loader: 'url-loader?name=images/[name].[ext]'
2017-11-15 15:13:49 +01:00
}
}, {
2017-12-07 16:21:27 +01:00
test: /\.(svg|glsl|d3sketch)$/,
2017-11-15 15:13:49 +01:00
use: {
loader: 'raw-loader'
}
2017-11-23 10:51:52 +01:00
}, {
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
2017-11-15 15:13:49 +01:00
}
]
},
plugins: [
2017-12-07 16:21:10 +01:00
new webpack.DefinePlugin({
'process.env': {
'TARGET': JSON.stringify(process.env.TARGET)
}
}),
2017-11-15 15:13:49 +01:00
new HTMLWebpackPlugin({
2017-11-15 16:12:33 +01:00
title: 'Doodle3D Core - Simple example',
2017-11-15 15:13:49 +01:00
template: require('html-webpack-template'),
inject: false,
2017-12-07 16:21:10 +01:00
scripts: appMode ? ['cordova.js'] : null,
2017-11-15 15:13:49 +01:00
appMountId: 'app'
}),
2017-12-07 16:21:10 +01:00
...(appMode ? [
new CordovaPlugin({
config: 'config.xml',
src: 'index.html',
platform: 'ios',
version: true
})
] : [])
2017-11-15 15:13:49 +01:00
],
devtool: "source-map",
devServer: {
contentBase: 'dist'
}
};