How to create webpack on geroku?

What is the best way to start a Webpack assembly after deployment to Heroku?

Paste the already attached version into the not-so-beautiful solution.

+6
source share
3 answers

Which app is this? If you use package.json, you can run webpack at the postinstall stage using npm scripts.

+5
source

You can install postinstall in your package.json on the following NODE_ENV=production webpack -p

Then set start to node

But you need to configure your web package for production by installing it in your webpack.config.js or webpack.config.js (production) file as the production configuration.

I installed everything in my webpack.config.js as follows.

 const path = require('path'); const webpack = require('webpack'); const debug = process.env.NODE_ENV !== "production"; module.exports = { entry: [ './src/index.js' ], output: { path: path.resolve(__dirname, 'src'), filename: 'bundle.js' }, devtool: debug ? "inline-sourcemap" : null, module: { loader: [{ exclude: /node_modules/, loader: 'babel', query: { presets: ['angular'] } }, { test: /\.css$/, loader: "style-loader!css-loader" }] }, devServer: { historyApiFallback: true, contentBase: 'src' }, plugins: debug ? [] : [ new webpack.optimize.DedupePlugin(), new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin({ mangle: {except: ['$', 'exports', 'require', 'app']}, compress: {warnings: false}, sourceMap: false }) ] } 

so as soon as the command starts npm run postinstall , the package will be generated in the directory according to webpack.config.js (output). But be sure to include the NODE_ENV=production webpack -p commands in your package.json package before running 'npm start'. See the example below.

 { "name": "", "version": "1.0.0", "description": "", "main": "./src/bundle.js", "engines": { "node": "6.4.0" }, "scripts": { "start": "node ./src/server.js", "postinstall": "NODE_ENV=production webpack -p" }, "author": "", "license": "ISC", "dependencies": ... 
+2
source

I solved this problem by placing devDependencies in normal dependencies, and I changed the postinstall script to:

 node_modules/.bin/webpack 
+1
source

Source: https://habr.com/ru/post/978965/


All Articles