【问题标题】:What is the right way to let the lazyloaded file (*.ts) to be compiled什么是让延迟加载文件(* .ts)被编译的正确方法
【发布时间】:2017-12-16 20:45:53
【问题描述】:

lazyLoading 通过 oclazyloader 为 angularjs 编写脚本文件时:

$stateProvider
.state('tokenReceived', {
    url: '/somurl',
    //templateUrl: '/views/index.html',
    controller: "controllers.loremCtrl",
    resolve: {
        deps: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load({
                files: [
                    scriptPath + 'loremCtrl.js'
                ],
                cache:false
            });
        }]
    }
})

我的 tsconfig.json 文件看起来像这样

{  
  "compilerOptions": {
    "module": "commonjs",
    "typeRoots": [
      "./node_modules/@types/"
    ],
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

webpack 里面定义的入口是这样的

module.exports = function (env) {
    return Merge(require(`./webpack.${env}.js`), {
        entry: {
            vendor: [
                "jquery",
                "toastr"
            ],
            rootApp: "./Scripts/rootApp.js",
        },
        resolve: {            
            extensions: [".ts", "tsx", ".js"]
        },
        module: {
            rules: [
                //NON-PRE                  
                { test: /\.ts?$/, loader: "ts-loader" },
                { test: /\.css$/, use: ExtractTextPlugin.extract({ use: ['css-loader'] }) },
                //PRE 
                { test: /(\.png|\.gif|\.ttf|\.eot|\.woff|\.svg)/, loader: "file-loader", enforce: "pre", },
                { test: /\.js$/, loader: "source-map-loader", enforce: "pre", }
            ]
        },
    }
}

什么是让延迟加载的文件(*.ts)被webpack2编译的正确方法?

一开始我在 tsconfig.json 中有 compileOnSave: true 但这不需要与 webpack 结合使用吗?我错过了什么吗?

“loremCtrl.ts”是否编译并保存在“rootApp.js”中?我应该如何使用 webpack 来编译延迟加载的文件?

【问题讨论】:

    标签: angularjs webpack oclazyload


    【解决方案1】:

    这似乎只是在开发中结合 webpack-dev-server 更新延迟加载的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-07
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      相关资源
      最近更新 更多