簡體   English   中英

從webpack輸出到更多文件

[英]Output from webpack to more files

是否有一些選項可以分別捆綁React Core和我的腳本? 例如兩個文件:

  1. bundle-ract.js (包括react,react-dom,redux,不可變)
  2. bundle.js (我的應用程序和腳本)

當然有這種方法。 您必須在webpack配置中定義多個條目。 與此類似:

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    entry: {
        'SubItems': './src/modules/sub-items/sub.items.module.js',
        'UniversalDiscovery': './src/modules/universal-discovery/universal.discovery.module.js',
        'MultiFileUpload': './src/modules/multi-file-upload/multi.file.upload.module.js',
    },
    output: {
        filename: '[name].module.js',
        path: path.resolve(__dirname, 'Resources/public/js'),
        library: ['eZ', 'modules', '[name]'],
        libraryTarget: 'umd',
        libraryExport: 'default',
    },
    devtool: 'source-map',
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }
        ]
    },
    externals: {
        'react': {
            root: 'React',
            commonjs2: 'react',
            commonjs: 'react',
            amd: 'react'
        },
        'react-dom': {
            root: 'ReactDOM',
            commonjs2: 'react-dom',
            commonjs: 'react-dom',
            amd: 'react-dom'
        }
    },
    plugins: [
        new CleanWebpackPlugin(['Resources']),
        new UglifyJSPlugin({
            sourceMap: true,
            uglifyOptions: {
                ecma: 6
            }
        })
    ]
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM