Webpack concat输出js文件将其包装在库中?

时间:2017-09-18 16:01:19

标签: javascript webpack gulp webpack-dev-server

我需要将webpack输出与其他文件连接起来,例如pre.js + bundle.js(the webpack output file) + after.js。我已经尝试了webpack concat插件,并将webpack与gulp结合起来,但我无法弄清楚如何获取输出文件并将其传递给concat任务。这样做的目的是将输出包装在自定义库中。

webpack.config.js

module.exports = {
    context: path.resolve(__dirname, 'src'),
    entry: './app.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        rules: [{
            test: /\.js$/,
            include: path.resolve(__dirname, 'src'),
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: [
                        ['es2015', {modules: false}]
                    ]
                }
            }]
        }
    ]},
     plugins: [
        new ConcatPlugin({
            useHash: true,
            sourceMap: true,
            name: 'flxeible',
            fileName: '[name].bundle.js',
            filesToConcat: ['pre.js','dist/bundle.js','after.js']
        })
    ]
};

这将连接已构建的bundle.js,而不是由webpack dev服务器生成和更新的var gulp = require('gulp'); var gutil = require('gulp-util') var webpack = require('webpack'); var WebpackDevServer = require('webpack-dev-server') var webpackConfig = require('./webpack.config.js') gulp.task('default', [ "webpack-dev-server"]) var myDevConfig = Object.create(webpackConfig); gulp.task("webpack-dev-server", function(callback){ new WebpackDevServer(webpack(myDevConfig), { stats: { colors: true } }).listen(8080, "localhost", function(err){ if(err) throw new gutil.PluginError("webpack-dev-server", err); gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html"); }) })

使用gulp

function printName(name) {
  console.log('Name is: ' , name);
}

printName.callAfter = function(time, name) {
  setTimeout(function() {
    printName(name)
  }, time);
}

printName.callAfter(3000, 'foo');

在第二种情况下,不确定如何在gulp中获取webpack输出。

1 个答案:

答案 0 :(得分:0)

您仅使用if let date = datePickerView.date { let fmt = DateFormatter() fmt.dateStyle = .medium fmt.timeStyle = .none fmt.timeZone = TimeZone(secondsFromGMT: 0) let title = fmt.string(from: date) print(title) } 来运行$serial_number_array = json_decode($this->input->post('serial_number_array_session')); if (isset($serial_number_array)) { if ($serial_number_array == null) { } else { $Serial_number_info_array = array(); foreach ($serial_number_array as $value) { $Serial_number_info_array['Issue_Number'] = $Issue; $Serial_number_info_array['status_serial_item'] = 1; $Item_name = $value->Item_Name_session; for ($a = 0; $a <= $loop_serial_number; $a++) { ***$serial_number = $value->serial_number_session["$a"];*** $this->Inventory_model->Update_serial_number_model($Item_name,$serial_number,$Serial_number_info_array); } } } } ?这不是必需的:https://webpack.js.org/guides/development/#using-webpack-dev-server

在不了解gulpwebpack-dev-server的内容+目的的情况下,很难给出好的建议。您可能希望调整BannerPlugin以输出页脚= pre.js,或将webpack配置为generate multiple targets(第一个after.jsafter.js + {{1然后检查various ways for shimming,或者通过三个后续导入(dist/bundle.js)将树文件合并到新的条目文件中。}} + pre.js之后)。祝你好运。