Webpack-从TS编译的带有JS的独立HTML文件

时间:2018-06-20 14:29:42

标签: angular webpack html-webpack-plugin

我已经成功使用Webpack构建了Angular 5项目。我需要添加一个带有javascript的独立HTML文件。该javascript将从.ts文件进行编译。我正在尝试使用HtmlWebpackPlugin,下面给出了示例代码。

    // Webpack config
    entry: {

        polyfills: './src/polyfills.ts',
        vendor: './src/vendor.ts',
        main: './src/main.ts',
        test: './src/test/test.ts'
    },
    ....
    new HtmlWebpackPlugin({
        template: 'src/test.html',
        filename: 'test/index.html',
        chunksSortMode: 'dependency',
        title: 'Example',
        chunks: ['test']
    }),
    ...

    // test.ts
    alert("I am here");

test/index.html已成功创建,脚本已添加到头部,但是当我尝试访问URL host/test/index.html时,出现错误test.bundle.js:1 Uncaught ReferenceError: webpackJsonp is not defined at。当我在同一文件中包含polyfills.js时出现错误,但是我正在尝试不使用这些导入的解决方案。我的要求是要有一个独立的编译代码。我做错了什么/还有其他解决方法吗?谢谢!

0 个答案:

没有答案
相关问题