diff --git a/app/react-native/package.json b/app/react-native/package.json index d2d78b903fb1..5716932f1b31 100644 --- a/app/react-native/package.json +++ b/app/react-native/package.json @@ -53,6 +53,7 @@ "file-loader": "^0.11.1", "find-cache-dir": "^1.0.0", "global": "^4.3.2", + "html-webpack-plugin": "^2.30.1", "json-loader": "^0.5.4", "json5": "^0.5.1", "postcss-loader": "^2.0.5", diff --git a/app/react-native/src/server/config/webpack.config.js b/app/react-native/src/server/config/webpack.config.js index ddd38a20d004..0e2f5c2ce09e 100644 --- a/app/react-native/src/server/config/webpack.config.js +++ b/app/react-native/src/server/config/webpack.config.js @@ -1,9 +1,10 @@ import path from 'path'; import webpack from 'webpack'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; import { OccurenceOrderPlugin, includePaths, excludePaths } from './utils'; -const config = { +const getConfig = options => ({ devtool: '#cheap-module-eval-source-map', entry: { manager: [require.resolve('../../manager')], @@ -14,6 +15,13 @@ const config = { publicPath: '/', }, plugins: [ + new HtmlWebpackPlugin({ + filename: 'index.html', + data: { + options: JSON.stringify(options), + }, + template: require.resolve('../index.html.ejs'), + }), new OccurenceOrderPlugin(), new webpack.HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), @@ -29,6 +37,6 @@ const config = { }, ], }, -}; +}); -export default config; +export default getConfig; diff --git a/app/react-native/src/server/config/webpack.config.prod.js b/app/react-native/src/server/config/webpack.config.prod.js index 841459f0c83f..9602f322a9a3 100644 --- a/app/react-native/src/server/config/webpack.config.prod.js +++ b/app/react-native/src/server/config/webpack.config.prod.js @@ -1,57 +1,67 @@ import path from 'path'; import webpack from 'webpack'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; import { OccurenceOrderPlugin, includePaths, excludePaths } from './utils'; -const config = { - bail: true, - devtool: '#cheap-module-source-map', - entry: { - manager: [path.resolve(__dirname, '../../manager')], - }, - output: { - path: path.join(__dirname, 'dist'), - filename: 'static/[name].bundle.js', - // Here we set the publicPath to ''. - // This allows us to deploy storybook into subpaths like GitHub pages. - // This works with css and image loaders too. - // This is working for storybook since, we don't use pushState urls and - // relative URLs works always. - publicPath: '/', - }, - plugins: [ - new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }), - new webpack.optimize.DedupePlugin(), - new webpack.optimize.UglifyJsPlugin({ - compress: { - screw_ie8: true, - warnings: false, - }, - mangle: { - screw_ie8: true, - }, - output: { - comments: false, - screw_ie8: true, - }, - }), - ], - module: { - loaders: [ - { - test: /\.jsx?$/, - loader: require.resolve('babel-loader'), - query: require('./babel.prod.js'), // eslint-disable-line - include: includePaths, - exclude: excludePaths, - }, +const getConfig = options => { + const config = { + bail: true, + devtool: '#cheap-module-source-map', + entry: { + manager: [path.resolve(__dirname, '../../manager')], + }, + output: { + path: path.join(__dirname, 'dist'), + filename: 'static/[name].bundle.js', + // Here we set the publicPath to ''. + // This allows us to deploy storybook into subpaths like GitHub pages. + // This works with css and image loaders too. + // This is working for storybook since, we don't use pushState urls and + // relative URLs works always. + publicPath: '/', + }, + plugins: [ + new HtmlWebpackPlugin({ + filename: 'index.html', + data: { + options: JSON.stringify(options), + }, + template: require.resolve('../index.html.ejs'), + }), + new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }), + new webpack.optimize.DedupePlugin(), + new webpack.optimize.UglifyJsPlugin({ + compress: { + screw_ie8: true, + warnings: false, + }, + mangle: { + screw_ie8: true, + }, + output: { + comments: false, + screw_ie8: true, + }, + }), ], - }, -}; + module: { + loaders: [ + { + test: /\.jsx?$/, + loader: require.resolve('babel-loader'), + query: require('./babel.prod.js'), // eslint-disable-line + include: includePaths, + exclude: excludePaths, + }, + ], + }, + }; -// Webpack 2 doesn't have a OccurenceOrderPlugin plugin in the production mode. -// But webpack 1 has it. That's why we do this. -if (OccurenceOrderPlugin) { - config.plugins.unshift(new OccurenceOrderPlugin()); -} + // Webpack 2 doesn't have a OccurenceOrderPlugin plugin in the production mode. + // But webpack 1 has it. That's why we do this. + if (OccurenceOrderPlugin) { + config.plugins.unshift(new OccurenceOrderPlugin()); + } +}; -export default config; +export default getConfig; diff --git a/app/react-native/src/server/index.html.ejs b/app/react-native/src/server/index.html.ejs new file mode 100644 index 000000000000..84b46693e476 --- /dev/null +++ b/app/react-native/src/server/index.html.ejs @@ -0,0 +1,34 @@ + + +
+ + +