【问题标题】:Find right solution to include React + TypeScript at the same time in Laravel Mix webpack.mix?在 Laravel Mix webpack.mix 中找到同时包含 React + TypeScript 的正确解决方案?
【发布时间】:2019-05-31 23:16:16
【问题描述】:

当我尝试连接时:

mix.ts('resources/assets/js/app.ts', 'public/js/app.js') .react('resources/js/app.ts', 'public/js/app.js');

出现错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.entry should be one of these: function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] -> The entry point(s) of the compilation.

所以,我是这样解决的:

`mix.react('resources/js/index.js', 'public/js/app.js')
.webpackConfig({
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
            },
        ],
    },
    resolve: {
        extensions: ['.ts', '.tsx'],
    }, 
})`

但我不确定它是否正确,有什么建议吗???我会很高兴,谢谢)

【问题讨论】:

    标签: javascript reactjs webpack laravel-mix


    【解决方案1】:

    现在回答为时已晚,但可能对有同样问题的人有所帮助。

    webpack.mix.js:

    mix.ts('resources/js/index.tsx', 'public/js/app.js').react();
    

    在你的 Laravel 刀片模板中关闭 body 标签之前添加以下脚本标签:

    <script src="{{ asset('js/app.js') }}"></script>
    

    【讨论】:

      猜你喜欢
      • 2015-04-12
      • 1970-01-01
      • 2012-06-19
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多