Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 创建js网页包配置_Webpack - Fatal编程技术网

Webpack 创建js网页包配置

Webpack 创建js网页包配置,webpack,Webpack,如何为js文件正确创建网页包配置文件 我需要为文件夹src/Components/Auth/js/modules创建网页包配置文件(文件夹内有js文件) const path = require('path') // This is common.js console.log('*** webpack started loading. ***'); /* webpack config object takes two parameters. 1. entry: firstFil

如何为js文件正确创建网页包配置文件

我需要为文件夹src/Components/Auth/js/modules创建网页包配置文件(文件夹内有js文件)

const path = require('path') // This is common.js

console.log('*** webpack started loading. ***');

/*
   webpack config object takes two parameters.
   1. entry: firstFile which need to be loaded.
   2. output:
      -path: directory name so it can store fully minified version of .js 
             files. need to specifiy fully qualified path.
      -filename: file name of minified file.
*/
  const config = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
  },
}

console.log('*** webpack loading completed. ***');

module.exports = config; // this is common.js
Webpack是一个开源JavaScript模块绑定器。其主要目的 是绑定JavaScript文件以在浏览器中使用



在项目目录的根目录中创建webpack.config.js文件

webpack.config.js

现在从您的终端类型运行
'webpack'

const path = require('path') // This is common.js

console.log('*** webpack started loading. ***');

/*
   webpack config object takes two parameters.
   1. entry: firstFile which need to be loaded.
   2. output:
      -path: directory name so it can store fully minified version of .js 
             files. need to specifiy fully qualified path.
      -filename: file name of minified file.
*/
  const config = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
  },
}

console.log('*** webpack loading completed. ***');

module.exports = config; // this is common.js
有关更多信息,请参阅下面的
package.json
文件。

{
  "name": "hello_webpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.19.0",
    "webpack-cli": "^3.1.0",
    "path": "^0.12.7"
  },
  "dependencies": {

  }
}

const path = require('path') // This is common.js

console.log('*** webpack started loading. ***');

/*
   webpack config object takes two parameters.
   1. entry: firstFile which need to be loaded.
   2. output:
      -path: directory name so it can store fully minified version of .js 
             files. need to specifiy fully qualified path.
      -filename: file name of minified file.
*/
  const config = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
  },
}

console.log('*** webpack loading completed. ***');

module.exports = config; // this is common.js