This time I will show you how to package webpacknode.js, what are the precautions for webpack packaging node.js, the following is a practical case, let's take a look.
Installation dependencies
The code is as follows:
npm install --save-dev webpack babel-loader babel-preset-es2015 babel-preset-stage-0
webpack configuration
webpack.config.js
'use strict'; const webpack = require('webpack'); let externals = _externals(); module.exports = { entry: { app: './app.js', }, target: 'node', output: { path: './build', filename: '[name].js' }, resolve: { extensions: ['', '.js'] }, externals: externals, node: { console: true, global: true, process: true, Buffer: true, filename: true, dirname: true, setImmediate: true }, module: { loaders: [ { test: /\.js$/, loader: 'babel', query: { presets: ['es2015','stage-0'] }, exclude: /node_modules/ } ] }, plugins: [ new webpack.optimize.UglifyJsPlugin() ] }; function _externals() { let manifest = require('./package.json'); let dependencies = manifest.dependencies; let externals = {}; for (let p in dependencies) { externals[p] = 'commonjs ' + p; } return externals; }
Project Directory
+controller +models +routes +service +test +util -app.js -config.json -gulpfile.js -models.js -package.json -pm2.json -webpack.config.js
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to make a small ball animation with js
How to use the $http service in angular
What are the three attributes of the javascript object
The above is the detailed content of How to package node.js with webpack. For more information, please follow other related articles on the PHP Chinese website!