对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

 

posted @ 2018-09-14 11:05  又回到了起点  阅读(138)  评论(0编辑  收藏  举报