summaryrefslogtreecommitdiff
path: root/client/web/webpack.config.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-06-01 19:47:08 -0400
committerJules Laplace <julescarbon@gmail.com>2017-06-01 19:47:08 -0400
commit3e72bfa56c860826429a842f6c128d78d4a930db (patch)
tree3cecd31c92d53fae32e9761b80802c82f3dcb7fa /client/web/webpack.config.js
parentb694bd511ceccd00d4a4c98f36f910d5fc5f79c4 (diff)
react-native-web port of fmf app
Diffstat (limited to 'client/web/webpack.config.js')
-rw-r--r--client/web/webpack.config.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/client/web/webpack.config.js b/client/web/webpack.config.js
new file mode 100644
index 0000000..d9425c1
--- /dev/null
+++ b/client/web/webpack.config.js
@@ -0,0 +1,104 @@
+/* eslint-disable */
+const enableOfflinePlugin = false
+
+const __DEV__ = process.env.NODE_ENV === 'development'
+const __OFFLINE__ = enableOfflinePlugin && !__DEV__
+
+const path = require('path')
+const glob = require('glob')
+const webpack = require('webpack')
+const config = require('./shared.webpack.config.js')
+
+const HtmlWebpackPlugin = require('html-webpack-plugin')
+const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
+
+const CopyWebpackPlugin = require('copy-webpack-plugin')
+const OfflinePlugin = require('offline-plugin')
+
+const vendorConfig = require('./vendor.webpack.config.js')
+const outputPath = path.join(__dirname, '/build/')
+
+
+const addAssetHtmlFiles = Object.keys(vendorConfig.entry).map((name) => {
+ const fileGlob = `${name}*.dll.js`
+ const paths = glob.sync(path.join(vendorConfig.output.path, fileGlob))
+ if (paths.length === 0) throw new Error(`Could not find ${fileGlob}!`)
+ if (paths.length > 1) throw new Error(`Too many files for ${fileGlob}! You should clean and rebuild.`)
+ return {
+ filepath: require.resolve(paths[0]),
+ includeSourcemap: false,
+ outputPath: 'javascript/vendor',
+ publicPath: '/javascript/vendor',
+ }
+})
+
+const plugins = [
+ ...Object.keys(vendorConfig.entry).map(name =>
+ new webpack.DllReferencePlugin({
+ context: process.cwd(),
+ manifest: require(path.join(vendorConfig.output.path, `${name}-manifest.json`)),
+ })),
+
+ new webpack.DefinePlugin({
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
+ __DEV__,
+ __OFFLINE__,
+ }),
+ new HtmlWebpackPlugin({
+ filename: 'index.html',
+ template: 'web/templates/index.ejs',
+ }),
+ new AddAssetHtmlPlugin(addAssetHtmlFiles),
+
+ new CopyWebpackPlugin([
+ // Workaround for AddAssetHtmlPlugin not copying compressed .gz files
+ { context: 'web/vendor/', from: '*.js.gz', to: 'javascript/vendor/' },
+ ]),
+
+ // Split out any remaining node modules
+ new webpack.optimize.CommonsChunkPlugin({
+ name: 'vendor/lib',
+ minChunks: module => module.context && module.context.indexOf('node_modules/') !== -1,
+ }),
+
+ ...(__DEV__ ? [] : [
+ ...config.productionPlugins,
+
+ // Add any app-specific production plugins here.
+ ])
+]
+
+// If offline plugin is enabled, it has to come last.
+if (__OFFLINE__) plugins.push(new OfflinePlugin())
+
+module.exports = {
+ devServer: {
+ contentBase: outputPath,
+ },
+ entry: {
+ app: path.join(__dirname, '../index.web.js')
+ },
+ module: {
+ loaders: [
+ {
+ test: /\.js$/,
+ exclude: /node_modules/,
+ // TODO: Set up react-hot-loader during development.
+ loaders: [ 'babel-loader?cacheDirectory=true' ],
+ },
+ ...config.loaders,
+ ]
+ },
+ output: {
+ path: outputPath,
+ filename: 'javascript/[name]-[hash:16].js',
+ publicPath: '/'
+ },
+ plugins: plugins,
+ resolve: {
+ alias: {
+ 'react-native': 'react-native-web'
+ },
+ extensions: [".web.js", ".js", ".json"]
+ }
+};