输出 | Output

输出(Output)

用法

  • filename 用于输出文件的文件名。

  • 目标输出目录 path 的绝对路径。

webpack.config.js

const config = { output: { filename: 'bundle.js', path: '/home/proj/public/assets' } }; module.exports = config;

多个入口点

{ 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

output: { path: "/home/proj/cdn/assets/[hash]", publicPath: "http://cdn.example.com/assets/[hash]/" }

__webpack_public_path__ = myRuntimePublicPath // rest of your application entry