te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Webpack - ignore loaders in require()? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webpack - ignore loaders in require()? - Stack Overflow

programmeradmin4浏览0评论

I have a TypeScript project which I am bundling with Webpack. It is a demo/docs app for an open source lib I am writing, so I want to show some of the source code as part of the docs.

In my webpack config I have:

 loaders: [
   { test: /\.ts$/, loader: 'ts'},
   { test: /\.css$/, loader: 'style!raw' },
   { test: /\.html/, loader: 'html' }
 ]

which works fine for transpiling and bundling my TypeScript files. In one of my app ponents I do this:

basicCodeT: string = require('./basic-example-cmp.html');
basicCodeC: string = require('!raw!./basic-example-cmp.ts');

to load the source code into a string which I then want to display in the docs.

As you can see, there is a leading ! in the second line which I discovered seems to "bypass" the default loaders from the config and loads the raw TypeScript as a string.

In my dev build this works, but when I do a "production" build with the UglifyJsPlugin and OccurrenceOrderPlugin, I get the following output:

ERROR in ./demo/src/basic-example-cmp.html
Module build failed: 
@ ./demo/src/demo-app.ts 24:26-61

which corresponds to the line in the source where I try to require the raw TypeScript.

So, I want to pass basic-example-cmp.ts through the TS piler as part of the app build, but also want to require it as raw text in the app.

My question then is: Is there a proper way to tell webpack to "ignore" loaders in specific require cases?

Is my way of prepending a ! correct? Is it a hack?

Update

Turns out my problem is simply due to the way Webpack handles HTML templates - it does not like the Angular 2 template syntax, see:

I have a TypeScript project which I am bundling with Webpack. It is a demo/docs app for an open source lib I am writing, so I want to show some of the source code as part of the docs.

In my webpack config I have:

 loaders: [
   { test: /\.ts$/, loader: 'ts'},
   { test: /\.css$/, loader: 'style!raw' },
   { test: /\.html/, loader: 'html' }
 ]

which works fine for transpiling and bundling my TypeScript files. In one of my app ponents I do this:

basicCodeT: string = require('./basic-example-cmp.html');
basicCodeC: string = require('!raw!./basic-example-cmp.ts');

to load the source code into a string which I then want to display in the docs.

As you can see, there is a leading ! in the second line which I discovered seems to "bypass" the default loaders from the config and loads the raw TypeScript as a string.

In my dev build this works, but when I do a "production" build with the UglifyJsPlugin and OccurrenceOrderPlugin, I get the following output:

ERROR in ./demo/src/basic-example-cmp.html
Module build failed: 
@ ./demo/src/demo-app.ts 24:26-61

which corresponds to the line in the source where I try to require the raw TypeScript.

So, I want to pass basic-example-cmp.ts through the TS piler as part of the app build, but also want to require it as raw text in the app.

My question then is: Is there a proper way to tell webpack to "ignore" loaders in specific require cases?

Is my way of prepending a ! correct? Is it a hack?

Update

Turns out my problem is simply due to the way Webpack handles HTML templates - it does not like the Angular 2 template syntax, see: https://github./webpack/webpack/issues/992

Share Improve this question edited Feb 29, 2016 at 11:29 Michael Bromley asked Feb 22, 2016 at 21:10 Michael BromleyMichael Bromley 4,8224 gold badges37 silver badges61 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

You can add two exclamation to ignore loaders in the webpack config file

!!raw!file.ts

one exclamation will only disable preloaders!

https://webpack.js/concepts/loaders/#inline

As far as I know that is the only way you are going to be able to load a file in two different ways. I expect the issue is that your paths are different in your production build.

I would suggest running webpack with the --display-error-details flag to get more info on why it fails.

Is there a proper way to tell webpack to "ignore" loaders in specific require cases?

Yes. Update your test in { test: /\.ts$/, loader: 'ts'}, as desired.

发布评论

评论列表(0)

  1. 暂无评论