zoukankan      html  css  js  c++  java
  • 对webpack的初步研究3

    Output配置output配置选项告诉webpack如何将编译后的文件写入磁盘。请注意,虽然可以有多个entry点,但只output指定了一个配置。

    • filename to use for the output file(s).

    webpack.config.js

    module.exports = {
      output: {
        filename: 'bundle.js',
      }
    };
    

    This configuration would output a single bundle.js file into the dist directory.

    如果您的配置创建了多个“块”(与多个入口点一样或使用CommonsChunkPlugin等插件时),则应使用替换来确保每个文件都具有唯一名称。

    module.exports = {
      entry: {
        app: './src/app.js',
        search: './src/search.js'
      },
      output: {
        filename: '[name].js',
        path: __dirname + '/dist'
      }
    };
    
    // writes to disk: ./dist/app.js, ./dist/search.js

    高级 

    以下是使用CDN和资产哈希的更复杂的示例:

    config.js

    module.exports = {
      //...
      output: {
        path: '/home/proj/cdn/assets/[hash]',
        publicPath: 'http://cdn.example.com/assets/[hash]/'
      }
    };
    

    如果publicPath在编译时不知道输出文件的最终结果,则可以将其留空并在运行时通过__webpack_public_path__入口点文件中变量动态设置

    __webpack_public_path__ = myRuntimePublicPath;
    
    // rest of your application entry
  • 相关阅读:
    字符串分割并按大小排序
    为人之气
    RMQ
    线段树
    算法中的数学
    动态规划(DP)
    图的表示
    广度优先搜索(BFS)
    深度优先搜索(DFS)
    MyBatis(3.2.3)
  • 原文地址:https://www.cnblogs.com/zhouyideboke/p/9645323.html
Copyright © 2011-2022 走看看