【问题标题】:Create js webpack config创建 js webpack 配置
【发布时间】:2019-02-08 22:45:39
【问题描述】:

如何正确创建js文件的webpack配置文件?

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

【问题讨论】:

    标签: webpack


    【解决方案1】:

    From wikipedia

    Webpack 是一个开源的 JavaScript 模块打包器。其主要目的 是捆绑 JavaScript 文件以便在浏览器中使用。

    npm install --save-dev webpack
    

    npm install --save-dev webpack-cli
    

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

    webpack.config.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'

    以下是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": {
    
      }
    }
    

    For Basic Example click here

    【讨论】:

      猜你喜欢
      • 2020-01-07
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 2017-10-04
      • 2020-10-07
      • 2023-01-30
      • 2018-01-30
      • 2019-04-04
      相关资源
      最近更新 更多